/// <summary> /// Creates a logical node (LN) and all of its children, including /// FCs, DO's, and DA's /// </summary> /// <param name="reader"></param> /// <returns> a LN node </returns> private NodeLN CreateLogicalNode2(XmlReader reader) { reader.Read(); var prefix = reader.GetAttribute("prefix"); var lnClass = reader.GetAttribute("lnClass"); var inst = reader.GetAttribute("inst"); var type = reader.GetAttribute("lnType"); // LN name is a combination of prefix, lnCLass, and inst var name = !String.IsNullOrWhiteSpace(prefix) ? String.Concat(prefix, lnClass, inst) : String.Concat(lnClass, inst); NodeLN logicalNode = new NodeLN(name); logicalNode.TypeId = type; Hashtable functionalConstraints = new Hashtable(); NodeBase nodeType; try { nodeType = _nodeTypes.Single(nt => nt.Name.Equals(type)); } catch (Exception e) { logger.LogError("SCL Parser: LN type template not found: " + type.ToString() + ", for Node: " + name.ToString() + ", Exception: " + e.Message); return(null); } // for each DO in the LNodeType foreach (var dataObject in nodeType.GetChildNodes()) { NodeBase doType = null; try { doType = _dataObjectTypes.Single(dot => dot.Name.Equals((dataObject as NodeDO).SCL_Type)); } catch (Exception e) { logger.LogError("SCL Parser: DO type template not found: " + (dataObject as NodeDO).SCL_Type + ", for LN type: " + nodeType.Name + ", in node: " + name.ToString() + ", Exception: " + e.Message); continue; } // for each DA in the DOType foreach (var dataAttribute in doType.GetChildNodes()) { var fc = (dataAttribute as NodeData).SCL_FCDesc; (dataAttribute as NodeData).SCL_DOName = dataObject.Name; NodeData newNode = new NodeData(dataAttribute.Name); newNode.SCL_Type = (dataAttribute as NodeData).SCL_Type; newNode.SCL_BType = (dataAttribute as NodeData).SCL_BType; newNode.SCL_DOName = (dataAttribute as NodeData).SCL_DOName; newNode.SCL_FCDesc = (dataAttribute as NodeData).SCL_FCDesc; // when the type is specified (ie. when it's a struct), get the struct child nodes if (!String.IsNullOrWhiteSpace(newNode.SCL_Type)) { var dataType = _dataAttributeTypes.Single(dat => dat.Name.Equals((newNode.SCL_Type))); foreach (NodeBase child in dataType.GetChildNodes()) { var tempChild = new NodeData(child.Name); tempChild.SCL_BType = (child as NodeData).SCL_BType; if (!String.IsNullOrWhiteSpace((child as NodeData).SCL_Type)) { var subDataType = _dataAttributeTypes.Single(dat => dat.Name.Equals((child as NodeData).SCL_Type)); foreach (NodeBase subChild in subDataType.GetChildNodes()) { var tempSubChild = new NodeData(subChild.Name); tempSubChild.SCL_BType = (subChild as NodeData).SCL_BType; tempChild.AddChildNode(subChild); } } newNode.AddChildNode(tempChild); } } if (!functionalConstraints.ContainsKey(fc)) { NodeFC nodeFC = new NodeFC(fc); nodeFC.ForceAddChildNode(newNode); functionalConstraints.Add(fc, nodeFC); } else { (functionalConstraints[fc] as NodeBase).ForceAddChildNode(newNode); } } } // for each hashtable element foreach (var key in functionalConstraints.Keys) { var doList = new List <NodeDO>(); // for each data attribute of the functional constraint foreach (var da in (functionalConstraints[key] as NodeBase).GetChildNodes()) { var doName = (da as NodeData).SCL_DOName; if (doList.Exists(x => x.Name.Equals(doName))) { doList.Single(x => x.Name.Equals(doName)).AddChildNode(da); } else { var temp = new NodeDO(doName); temp.AddChildNode(da); doList.Add(temp); } } var nodeFC = new NodeFC(key as string); foreach (NodeDO x in doList) { nodeFC.AddChildNode(x); } nodeFC.SortImmediateChildren(); // alphabetical logicalNode.AddChildNode(nodeFC); } logicalNode.SortImmediateChildren(); // alphabetical return(logicalNode); }
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!"); } } }
void OnActivateNVLClick(object sender, EventArgs e) { NodeVL vl = (NodeVL)(sender as ToolStripItem).Tag; NodeBase ur = null; Iec61850State iecs = vl.GetIecs(); if (iecs != null) { do { ur = (NodeData)iecs.ied.FindNodeByValue(scsm_MMS_TypeEnum.visible_string, vl.Address, ref ur); if (ur == null) { MessageBox.Show("Suitable URCB not found, list cannot be activated!"); return; } } while (!ur.Parent.Name.ToLower().Contains("rcb")); vl.urcb = (NodeData)ur; if (vl.urcb != null) { NodeData d = (NodeData)vl.urcb.Parent; List <NodeData> ndar = new List <NodeData>(); NodeBase b; if ((b = d.FindChildNode("Resv")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } if ((b = d.FindChildNode("DatSet")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = ((NodeData)b).DataValue; ndar.Add(n); } if ((b = d.FindChildNode("OptFlds")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = new byte[] { 0x7c, 0x00 }; n.DataParam = 6; ndar.Add(n); } if ((b = d.FindChildNode("TrgOps")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = new byte[] { 0x74 }; n.DataParam = 2; ndar.Add(n); } if ((b = d.FindChildNode("RptEna")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } if ((b = d.FindChildNode("GI")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } iecs.Send(ndar.ToArray(), d.CommAddress, ActionRequested.Write); vl.Activated = true; } } else { MessageBox.Show("Basic structure not found!"); } }
public void BuildIECModelFromMMSModel() { iec.DefineNVL = ied.DefineNVL; iec.Revision = ied.Revision; iec.VendorName = ied.VendorName; iec.ModelName = ied.ModelName; foreach (NodeLD ld in ied.GetChildNodes()) // LD level { NodeLD ild = new NodeLD(ld.Name); ild.IsIecModel = true; ild = (NodeLD)iec.AddChildNode(ild); foreach (NodeLN ln in ld.GetChildNodes()) // LN level { NodeLN iln = new NodeLN(ln.Name); iln.IsIecModel = true; iln = (NodeLN)ild.AddChildNode(iln); foreach (NodeFC fc in ln.GetChildNodes()) // FC level - skipping { if (fc.Name == "RP" || fc.Name == "BR") { continue; } // keep knowing FC for DA foreach (NodeDO dO in fc.GetChildNodes()) // DO level { NodeDO ido = new NodeDO(dO.Name); ido.IsIecModel = true; // AddChildNode returns original object if the same name found (new object is forgotten) ido = (NodeDO)iln.AddChildNode(ido); // At this point, it can happen that we get DO more than once (same DO in several FC) // For DOs, this is ok, FC is not relevant for DOs // Next level is peculiar: can be DO (subDataObject) or a DA // At this point, we will distinguish between DO and DA as follows: // At the first guess, we suppose DA // We will LINK the corresponding DA from MMS tree, and record the FC // If another object with the same name comes in (from another FC branch in MMS tree) // That means that we are not DA but DO (multiple FCs) // And this all has to be done recursively foreach (NodeBase da in dO.GetChildNodes()) { recursiveLinkDA(da, ido, fc); } } } } } // Add rcbs to LNs foreach (NodeLD ld in urcbs.GetChildNodes()) // LD level { foreach (NodeRCB urcb in ld.GetChildNodes()) { NodeBase ln = iec.FindNodeByAddress(ld.Name, urcb.Name.Remove(urcb.Name.IndexOf("$"))); if (ln != null) { ln.LinkChildNodeByName(urcb); } } } foreach (NodeLD ld in brcbs.GetChildNodes()) // LD level { foreach (NodeRCB brcb in ld.GetChildNodes()) { NodeBase ln = iec.FindNodeByAddress(ld.Name, brcb.Name.Remove(brcb.Name.IndexOf("$"))); if (ln != null) { ln.LinkChildNodeByName(brcb); } } } // Add datasets to LNs foreach (NodeLD ld in lists.GetChildNodes()) // LD level { foreach (NodeVL vl in ld.GetChildNodes()) { NodeBase ln = iec.FindNodeByAddress(ld.Name, vl.Name.Remove(vl.Name.IndexOf("$"))); if (ln != null) { ln.LinkChildNodeByName(vl); } } } }
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; } } } } } }
public void DeleteNVL(NodeVL nvl) { NodeBase[] ndarr = new NodeBase[1]; ndarr[0] = nvl; iecs.Send(ndarr, nvl.CommAddress, ActionRequested.DeleteNVL); }
public void ActivateNVL(NodeVL vl) { //Logger.getLogger().LogError("Function not active, try to configure an RCB!"); //return; NodeBase ur = null; Iec61850State iecs = vl.GetIecs(); bool retry; if (iecs != null) { do { ur = (NodeData)iecs.DataModel.ied.FindNodeByValue(scsm_MMS_TypeEnum.visible_string, vl.IecAddress, ref ur); if (ur == null || ur.Parent == null) { Logger.getLogger().LogError("Suitable URCB not found, list cannot be activated!"); return; } retry = !ur.Parent.Name.ToLower().Contains("rcb"); vl.urcb = (NodeData)ur; NodeData d = (NodeData)vl.urcb.Parent; NodeData b; if ((b = (NodeData)d.FindChildNode("Resv")) != null) { // Resv is always a boolean // If true then the rcb is occupied and we need to find another one if ((bool)b.DataValue) { retry = true; } } } while (retry); if (vl.urcb != null) { NodeData d = (NodeData)vl.urcb.Parent; List <NodeData> ndar = new List <NodeData>(); NodeBase b; if ((b = d.FindChildNode("Resv")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } if ((b = d.FindChildNode("DatSet")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = ((NodeData)b).DataValue; ndar.Add(n); } if ((b = d.FindChildNode("OptFlds")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = new byte[] { 0x7c, 0x00 }; n.DataParam = 6; ndar.Add(n); } if ((b = d.FindChildNode("TrgOps")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = new byte[] { 0x74 }; n.DataParam = 2; ndar.Add(n); } if ((b = d.FindChildNode("RptEna")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } if ((b = d.FindChildNode("GI")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = true; ndar.Add(n); } iecs.Send(ndar.ToArray(), d.CommAddress, ActionRequested.Write); vl.Activated = true; } } else { Logger.getLogger().LogError("Basic structure not found!"); } }
private void CreateSDO_DA(NodeBase dataObject, NodeBase doType) { // for each DA in the DOType foreach (var dataAttribute in doType.GetChildNodes()) { if (dataAttribute is NodeDO) { // SDO (sub Data Object) NodeBase subDoType = null; try { subDoType = _dataObjectTypes.Single(dot => dot.Name.Equals((dataAttribute as NodeDO).SCL_Type)); } catch (Exception e) { logger.LogError("SCL Parser: SDO type template not found: " + (dataAttribute as NodeDO).SCL_Type + ", for DO type: " + doType.Name + ", for LN type: " + doType.Parent.Name + ", in node: " + dataObject.Parent.Name + ", Exception: " + e.Message); continue; } NodeDO subDataObject = new NodeDO(dataAttribute.Name); subDataObject.SCL_ArraySize = (dataAttribute as NodeDO).SCL_ArraySize; dataObject.AddChildNode(subDataObject); if (subDataObject.SCL_ArraySize > 0) { for (int i = 0; i < subDataObject.SCL_ArraySize; i++) { NodeDO arrDataObject = new NodeDO("[" + i.ToString() + "]"); subDataObject.AddChildNode(arrDataObject); arrDataObject.SCL_UpperDOName = dataObject.Name; foreach (var dataAttribute2 in subDoType.GetChildNodes()) { if (dataAttribute2 is NodeDO) { CreateSDO_DA(arrDataObject, subDoType); } else { CreateDataAttributesIEC(arrDataObject, dataAttribute2); } } } } else { foreach (var dataAttribute2 in subDoType.GetChildNodes()) { if (dataAttribute2 is NodeDO) { CreateSDO_DA(subDataObject, subDoType); } else { CreateDataAttributesIEC(subDataObject, dataAttribute2); } } } } if (dataAttribute is NodeData && !(dataAttribute is NodeDO)) { CreateDataAttributesIEC(dataObject, dataAttribute); } } }
/// <summary> /// Reads through the specified SCL file and creates a logical tree /// </summary> /// <param name="fileName"></param> /// <param name="env"></param> /// <returns>IECS tree state to be displayed</returns> public List <Iec61850Model> CreateTree(String fileName) //, Env env) { // Model [0] is a master for types etc. _dataModels.Add(new Iec61850State().DataModel); _nodeTypes = new List <NodeBase>(); _dataObjectTypes = new List <NodeBase>(); _dataAttributeTypes = new List <NodeBase>(); int i = 0; logger.LogInfo("Reading SCL file " + fileName); XDocument doc = XDocument.Load(fileName); XNamespace ns = doc.Root.Name.Namespace; GetTypes(doc, ns); _dataModels[0].enums.SortImmediateChildren(); //logger.LogInfo("Reading XML tree."); foreach (XElement ied in doc.Root.Elements(ns + "IED")) { // Create model. Model 0 (master model) is already created above if (i > 0) { _dataModels.Add(new Iec61850State().DataModel); } XAttribute a = ied.Attribute("name"); if (a != null) { _dataModels[i].ied = new NodeIed(a.Value, _dataModels[i]); } else { continue; // cannot proceed } if (a != null) { _dataModels[i].iec = new NodeIed(a.Value, _dataModels[i]); } else { continue; // cannot proceed } _dataModels[i].iec.IsIecModel = true; a = ied.Attribute("manufacturer"); if (a != null) { _dataModels[i].ied.VendorName = a.Value; } if (a != null) { _dataModels[i].iec.VendorName = a.Value; } a = ied.Attribute("type"); if (a != null) { _dataModels[i].ied.ModelName = a.Value; } if (a != null) { _dataModels[i].iec.ModelName = a.Value; } a = ied.Attribute("revision"); if (a != null) { _dataModels[i].ied.Revision = a.Value; } if (a != null) { _dataModels[i].iec.Revision = a.Value; } int ldidx = 0; // IEC 61850 Tree CreateLogicalDevicesIEC(_dataModels[i].iec, ied.Descendants(ns + "LDevice"), ns); ldidx = 0; foreach (XElement ld in ied.Descendants(ns + "LDevice")) { NodeBase ldroot = _dataModels[i].iec.GetChildNode(ldidx++); int lnidx = 0; IEnumerable <XElement> lns = (from el in ld.Elements() where el.Name.LocalName.StartsWith("LN") select el); int cnt = lns.Count(); foreach (XElement ln in lns) { NodeBase lnroot = ldroot.GetChildNode(lnidx++); ReadDataInstanceValues(lnroot, ln.Elements(ns + "DOI"), ns); } } // Ied Tree makeIedModelFromIecModel(_dataModels[i], _dataModels[i].iec); i++; } return(_dataModels); }
void makeIedModelFromIecModel(Iec61850Model model, NodeBase iec) { foreach (NodeBase child in iec.GetChildNodes()) { if ((child is NodeData && !(child is NodeDO)) || child is NodeVLM) { // First DataAttribute child // Create the whole path down to Ied List <NodeBase> path = new List <NodeBase>(); NodeBase nb = child.Parent; while (nb != null && !(nb is NodeIed)) { path.Add(nb); nb = nb.Parent; } NodeBase subtree = model.ied; string fc = ""; if (child is NodeData && !(child is NodeDO)) { fc = (child as NodeData).SCL_FCDesc; if (String.IsNullOrEmpty(fc)) { logger.LogError("FC is empty for DataAttribute: " + child.IecAddress); continue; } } path.Reverse(); foreach (NodeBase pnb in path) { if (pnb is NodeLD) { subtree = subtree.AddChildNode(new NodeLD(pnb.Name)); } else if (pnb is NodeLN) { subtree = subtree.AddChildNode(new NodeLN(pnb.Name)); // Inserting the FC level if (!String.IsNullOrEmpty(fc)) // due to VLM { subtree = subtree.AddChildNode(new NodeFC(fc)); } } else if (pnb is NodeDO) { subtree = subtree.AddChildNode(new NodeDO(pnb.Name)); } else if (pnb is NodeRCB) { subtree = subtree.AddChildNode(new NodeRCB(pnb.Name)); (subtree as NodeRCB).isBuffered = (pnb as NodeRCB).isBuffered; if ((pnb as NodeRCB).isBuffered) { model.brcbs.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(subtree); } else { model.urcbs.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(subtree); } } else if (pnb is NodeVL) { //subtree = subtree.AddChildNode(new NodeVL(pnb.Name)); model.lists.AddChildNode(new NodeLD(path[0].Name)).LinkChildNodeByName(pnb); } } if (!(child is NodeVLM)) { subtree.LinkChildNodeByName(child); } else { // Fill the gap -> find the link for VLM nodes (child as NodeVLM).LinkedNode = model.iec.FindSubNode(child.Name); if ((child as NodeVLM).LinkedNode == null) { logger.LogWarning("DataSet " + child.Parent.IecAddress + ": node " + child.Name + " not found in the model!"); } } } else { // Recursive call makeIedModelFromIecModel(model, child); } } }
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); } } }
public Iec61850State sclParse(XmlDocument SclDoc) { XmlNodeList IEDNodes = SclDoc.GetElementsByTagName("IED"); XmlNodeList LDeviceNodes = SclDoc.GetElementsByTagName("LDevice"); XmlNodeList LNodeTypeNodes = SclDoc.GetElementsByTagName("LNodeType"); XmlNodeList DOTypeNodes = SclDoc.GetElementsByTagName("DOType"); XmlNodeList LN0Node = SclDoc.GetElementsByTagName("LN0"); XmlNodeList LNNodes = SclDoc.GetElementsByTagName("LN"); XmlNodeList DATypeNodes = SclDoc.GetElementsByTagName("DAType"); XmlNodeList DataSets = SclDoc.GetElementsByTagName("DataSet"); XmlNodeList GSE = SclDoc.GetElementsByTagName("GSE"); NodeBase LDNb, LNNb, NLNb = null; Iec61850State iecf = new Iec61850State(); foreach (XmlNode IEDNode in IEDNodes) { foreach (XmlNode LDeviceNode in LDeviceNodes) { string LDName = getLDName(IEDNode, LDeviceNode); if (LDName != null) { LDNb = iecf.DataModel.ied.AddChildNode(new NodeLD(LDName)); if (DataSets.Count > 0) { NLNb = iecf.DataModel.lists.AddChildNode(new NodeLD(iecf.DataModel.ied.GetActualChildNode().Name)); iecf.DataModel.ied.DefineNVL = true; } foreach (XmlNode LNNode in LDeviceNode.ChildNodes) { if (LNNode.Name == "LN") { string LNNodeName = getLNNodeName(LNNode); if (LNNodeName != null) { LNNb = LDNb.AddChildNode(new NodeLN(LNNodeName)); processLN(LNNode, LNNb, LNodeTypeNodes, DOTypeNodes, DATypeNodes); foreach (XmlNode LNNodeCn in LNNode.ChildNodes) { if (LNNodeCn.Name == "DOI") { processDOI(getStringAttribute(LNNode, "lnType"), getStringAttribute(LNNodeCn, "name"), LNNodeCn, LNNb, LNodeTypeNodes, DOTypeNodes, DATypeNodes); } } } } } foreach (XmlNode LNNode in LDeviceNode.ChildNodes) { if (LNNode.Name == "LN0") { string LNNodeName = getLNNodeName(LNNode); if (LNNodeName != null) { LNNb = LDNb.AddChildNode(new NodeLN(LNNodeName)); processLN(LNNode, LNNb, LNodeTypeNodes, DOTypeNodes, DATypeNodes); foreach (XmlNode LNNodeCn in LNNode.ChildNodes) { switch (LNNodeCn.Name) { case "DOI": processDOI(getStringAttribute(LNNode, "lnType"), getStringAttribute(LNNodeCn, "name"), LNNodeCn, LNNb, LNodeTypeNodes, DOTypeNodes, DATypeNodes); break; case "ReportControl": processReportControl(LNNodeCn, LNNb); break; case "GSEControl": processGSEControl(LNNodeCn, LNNb, DataSets, GSE); break; case "DataSet": processDataSet(LNNodeCn, NLNb, iecf, getStringAttribute(IEDNode, "name"), getStringAttribute(LNNode, "lnClass")); break; } } } break; } } } } } return(iecf); }
private void processReportControl(XmlNode LNNodeCn, NodeBase LNNb) { NodeBase lnfc = LNNb.AddChildNode(new NodeFC("RP")); string[] rptIDSplit = LNNodeCn.Attributes.GetNamedItem("rptID").Value.ToString().Split('$'); NodeBase lnfccn = lnfc.AddChildNode(new NodeData(rptIDSplit[rptIDSplit.Length - 1])); foreach (XmlAttribute Attr in LNNodeCn.Attributes) { NodeBase nd = null; switch (Attr.Name.ToLower()) { case "rptid": nd = new NodeData("RptId"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (nd as NodeData).StringValue = Attr.Value; lnfccn.AddChildNode(nd); break; case "confrev": nd = new NodeData("ConfRev"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.unsigned; (nd as NodeData).DataValue = Attr.Value; lnfccn.AddChildNode(nd); break; case "intgpd": nd = new NodeData("IntgPd"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.unsigned; (nd as NodeData).DataValue = Attr.Value; lnfccn.AddChildNode(nd); break; case "datset": nd = new NodeData("DatSet"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (nd as NodeData).StringValue = Attr.Value; lnfccn.AddChildNode(nd); break; case "buftime": nd = new NodeData("BufTm"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.unsigned; (nd as NodeData).DataValue = Attr.Value; lnfccn.AddChildNode(nd); break; } } foreach (XmlNode LNNodeCnCn in LNNodeCn.ChildNodes) { NodeBase nd = null; switch (LNNodeCnCn.Name.ToLower()) { case "trgops": nd = new NodeData("TrgOps"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.bit_string; lnfccn.AddChildNode(nd); break; case "optfields": nd = new NodeData("OptFlds"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.bit_string; lnfccn.AddChildNode(nd); break; case "rptenabled": nd = new NodeData("RprEna"); (nd as NodeData).DataType = scsm_MMS_TypeEnum.boolean; (nd as NodeData).DataValue = LNNodeCnCn.Value; lnfccn.AddChildNode(nd); break; } } }
private void processGSEControl(XmlNode LNNodeCn, NodeBase LNNb, XmlNodeList DataSets, XmlNodeList GSE) { NodeBase LNFc = LNNb.AddChildNode(new NodeFC("GO")); NodeBase DO = LNFc.AddChildNode(new NodeData(getStringAttribute(LNNodeCn, "name"))); NodeBase Nd = new NodeData("GoID"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (Nd as NodeData).DataValue = getStringAttribute(LNNodeCn, "appID"); DO.AddChildNode(Nd); Nd = new NodeData("DatSet"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (Nd as NodeData).DataValue = LNNb.IecAddress + "$" + getStringAttribute(LNNodeCn, "datSet"); DO.AddChildNode(Nd); if (GSE.Count > 0) { foreach (XmlNode GSENode in GSE) { if (GSENode.Name == "GSE" && getStringAttribute(LNNodeCn, "name") == getStringAttribute(GSENode, "cbName")) { foreach (XmlNode GSENodeCn in GSENode.ChildNodes) { if (GSENodeCn.Name == "Address") { Nd = new NodeData("DstAddress"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.structure; NodeBase DA = DO.AddChildNode(Nd); foreach (XmlNode GSENodeCnCn in GSENodeCn.ChildNodes) { switch (getStringAttribute(GSENodeCnCn, "type")) { case "MAC-Address": Nd = new NodeData("Addr"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (Nd as NodeData).DataValue = GSENodeCnCn.InnerText; DA.AddChildNode(Nd); break; case "APPID": Nd = new NodeData("APPID"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (Nd as NodeData).DataValue = Convert.ToUInt32(GSENodeCnCn.InnerText).ToString(); DA.AddChildNode(Nd); break; case "VLAN-PRIORITY": Nd = new NodeData("PRIORITY"); (Nd as NodeData).DataType = scsm_MMS_TypeEnum.visible_string; (Nd as NodeData).DataValue = GSENodeCnCn.InnerText; DA.AddChildNode(Nd); break; } } } break; } } } } }
internal override NodeBase FindNodeByValue(scsm_MMS_TypeEnum dataType, object dataValue, ref NodeBase ContinueAfter) { if (dataValue == null) { return(null); } NodeBase res = null; if (_childNodes.Count > 0) { foreach (NodeBase b in _childNodes) { res = b.FindNodeByValue(dataType, dataValue, ref ContinueAfter); if (res != null && ContinueAfter == null) { return(res); } if (res != null && ContinueAfter != null && res == ContinueAfter) { ContinueAfter = null; } } } else { if (dataType == this.DataType && this.DataValue != null && dataValue.ToString() == DataValue.ToString()) { return(this); } } return(null); }
/// <summary> /// Creates a DA node from parsed XML /// </summary> /// <param name="reader"></param> /// <returns></returns> private void CreateDataAttributes(NodeBase root, IEnumerable <XElement> elements, XNamespace ns) { foreach (XElement el in elements) { if (el.Attribute("name") != null) { NodeData data = new NodeData(el.Attribute("name").Value); if (el.Attribute("fc") != null) { data.SCL_FCDesc = el.Attribute("fc").Value; } else if (root is NodeData && !(root is NodeDO)) { data.SCL_FCDesc = (root as NodeData).SCL_FCDesc; } var bType = el.Attribute("bType"); if (bType == null) { XElement en = el.Element(ns + "Val"); if (en != null) { data.DataValue = en.Value; } // Inheritance if (root is NodeData && !(root is NodeDO)) { data.SCL_BType = (root as NodeData).SCL_BType; } } else { data.SCL_BType = bType.Value; if (data.SCL_BType.Equals("Struct") && null != el.Attribute("type")) { data.SCL_Type = el.Attribute("type").Value; } else if (data.SCL_BType.Equals("Enum")) { data.SCL_BType = String.Concat(data.SCL_BType, " (Integer)"); if (null != el.Attribute("type")) { data.SCL_Type = el.Attribute("type").Value; } } } IEC61850.Common.TriggerOptions trgOptions = IEC61850.Common.TriggerOptions.NONE; XAttribute a = el.Attribute("dchg"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.DATA_CHANGED; } a = el.Attribute("qchg"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.QUALITY_CHANGED; } a = el.Attribute("dupd"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.DATA_UPDATE; } data.SCL_TrgOps = (byte)trgOptions; // Inheritance if ((root is NodeData && !(root is NodeDO)) && trgOptions == IEC61850.Common.TriggerOptions.NONE) { data.SCL_TrgOps = (root as NodeData).SCL_TrgOps; } int cnt = 0; if (el.Attribute("count") != null) { int.TryParse(el.Attribute("count").Value, out cnt); } data.SCL_ArraySize = cnt; root.AddChildNode(data); } } }
public void SendCommand(NodeBase data, CommandParams cPar, ActionRequested how) { if (data != null) { Logger.getLogger().LogInfo("Sending command " + data.IecAddress); NodeData d = (NodeData)data.Parent; if (d != null) { NodeBase b, c; 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; if (d.Name == "SBO" || d.Name == "SBOw") { n.DataValue = m_ctlNum; } else { 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) { if (d.Name == "Oper" && cPar.SBOdiffTime && cPar.SBOrun) { cPar.T.AddMilliseconds(cPar.SBOtimeout); } Scsm_MMS.ConvertToUtcTime(cPar.T, btm); } ndar.Add(n); } if ((b = d.FindChildNode("Test")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; n.DataValue = cPar.Test; ndar.Add(n); } if ((b = d.FindChildNode("Check")) != null) { NodeData n = new NodeData(b.Name); n.DataType = ((NodeData)b).DataType; byte sync = 0x80; byte intl = 0x40; byte check = 0; if (cPar.synchroCheck) { check |= sync; } if (cPar.interlockCheck) { check |= intl; } n.DataValue = new byte[] { check }; n.DataParam = ((NodeData)b).DataParam; ndar.Add(n); } iecs.Send(ndar.ToArray(), d.CommAddress, how); } else { Logger.getLogger().LogError("Basic structure for a command not found at " + data.IecAddress + "!"); } } }
/// <summary> /// Reads through a report subtree and creates a report from it /// </summary> /// <param name="reader"></param> /// <param name="nodeName"></param> /// <param name="deviceName"></param> /// <returns> a RP node </returns> private void CreateReports(NodeBase lnode, IEnumerable <XElement> elements, XNamespace ns) { if (lnode == null || elements == null || lnode.Parent == null || lnode.Parent.Parent == null) { Logger.getLogger().LogError("CreateReports: Something is null"); } // We are at the LN level, up 2 levels is an ied Iec61850Model _dataModel = (lnode.Parent.Parent as NodeIed).Model; foreach (XElement el in elements) { List <NodeRCB> nodeRCBs = new List <NodeRCB>(); XAttribute a = el.Attribute("buffered"); bool buffered = a != null ? (a.Value.ToLower() == "true") : false; string fc = buffered ? "BR" : "RP"; a = el.Attribute("indexed"); bool indexed = a != null ? (a.Value.ToLower() == "true") : true; // default true??? uint maxRptEnabled = 1; XElement xeRptEnabled = el.Element(ns + "RptEnabled"); if (xeRptEnabled != null) { a = xeRptEnabled.Attribute("max"); try { maxRptEnabled = uint.Parse(a.Value); } catch { } } // correction necessary??? if (!indexed) { maxRptEnabled = 1; } if (maxRptEnabled < 1) { maxRptEnabled = 1; } if (maxRptEnabled > 99) { maxRptEnabled = 99; } for (int i = 0; i < maxRptEnabled; i++) { nodeRCBs.Add(new NodeRCB(el.Attribute("name").Value + (indexed ? (i + 1).ToString("D2") : ""))); lnode.AddChildNode(nodeRCBs[i]); nodeRCBs[i].isBuffered = buffered; } // rptID NodeData RptId = new NodeData("RptID"); RptId.SCL_FCDesc = fc; RptId.DataType = scsm_MMS_TypeEnum.visible_string; a = el.Attribute("rptID"); RptId.DataValue = a != null ? a.Value : ""; // datSet NodeData DatSet = new NodeData("DatSet"); DatSet.SCL_FCDesc = fc; DatSet.DataType = scsm_MMS_TypeEnum.visible_string; a = el.Attribute("datSet"); DatSet.DataValue = a != null ? a.Value : null; // null accepted // confRev NodeData ConfRev = new NodeData("ConfRev"); ConfRev.SCL_FCDesc = fc; ConfRev.DataType = scsm_MMS_TypeEnum.unsigned; a = el.Attribute("confRev"); try { ConfRev.DataValue = uint.Parse(a.Value); } catch { ConfRev.DataValue = (uint)1; } // bufTime NodeData BufTm = new NodeData("BufTm"); BufTm.SCL_FCDesc = fc; BufTm.DataType = scsm_MMS_TypeEnum.unsigned; a = el.Attribute("bufTime"); try { BufTm.DataValue = uint.Parse(a.Value); } catch { BufTm.DataValue = (uint)0; } // intgPd NodeData IntgPd = new NodeData("IntgPd"); IntgPd.SCL_FCDesc = fc; IntgPd.DataType = scsm_MMS_TypeEnum.unsigned; a = el.Attribute("intgPd"); try { IntgPd.DataValue = uint.Parse(a.Value); } catch { IntgPd.DataValue = (uint)0; } // <TrgOps dchg="true" qchg="false" dupd="false" period="true" /> NodeData TrgOps = new NodeData("TrgOps"); TrgOps.SCL_FCDesc = fc; TrgOps.DataType = scsm_MMS_TypeEnum.integer; IEC61850.Common.TriggerOptions trgOptions = IEC61850.Common.TriggerOptions.NONE; XElement xeTrgOps = el.Element(ns + "TrgOps"); if (xeTrgOps != null) { a = xeTrgOps.Attribute("dchg"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.DATA_CHANGED; } a = xeTrgOps.Attribute("qchg"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.QUALITY_CHANGED; } a = xeTrgOps.Attribute("dupd"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.DATA_UPDATE; } a = xeTrgOps.Attribute("period"); if ((a != null ? a.Value : "false").ToLower() == "true") { trgOptions |= IEC61850.Common.TriggerOptions.INTEGRITY; } a = xeTrgOps.Attribute("gi"); if ((a != null ? a.Value : "true").ToLower() == "true") // default true { trgOptions |= IEC61850.Common.TriggerOptions.GI; } } TrgOps.DataValue = trgOptions; // <OptFields seqNum="true" timeStamp="true" dataSet="true" reasonCode="true" dataRef="false" entryID="true" configRef="true" bufOvfl="true" /> NodeData OptFlds = new NodeData("OptFlds"); OptFlds.SCL_FCDesc = fc; OptFlds.DataType = scsm_MMS_TypeEnum.integer; IEC61850.Common.ReportOptions rptOptions = IEC61850.Common.ReportOptions.NONE; XElement xeOptFields = el.Element(ns + "OptFields"); if (xeOptFields != null) { a = xeOptFields.Attribute("seqNum"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.SEQ_NUM; } a = xeOptFields.Attribute("timeStamp"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.TIME_STAMP; } a = xeOptFields.Attribute("dataSet"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.DATA_SET; } a = xeOptFields.Attribute("reasonCode"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.REASON_FOR_INCLUSION; } a = xeOptFields.Attribute("dataRef"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.DATA_REFERENCE; } a = xeOptFields.Attribute("entryID"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.ENTRY_ID; } a = xeOptFields.Attribute("configRef"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.CONF_REV; } a = xeOptFields.Attribute("bufOvfl"); if ((a != null ? a.Value : "false").ToLower() == "true") { rptOptions |= IEC61850.Common.ReportOptions.BUFFER_OVERFLOW; } } OptFlds.DataValue = rptOptions; for (int i = 0; i < maxRptEnabled; i++) { nodeRCBs[i].AddChildNode(RptId); nodeRCBs[i].AddChildNode(DatSet); nodeRCBs[i].AddChildNode(ConfRev); nodeRCBs[i].AddChildNode(OptFlds); nodeRCBs[i].AddChildNode(BufTm); nodeRCBs[i].AddChildNode(TrgOps); nodeRCBs[i].AddChildNode(IntgPd); } } }
public void ReadData(NodeBase data) { NodeBase[] ndarr = new NodeBase[1]; ndarr[0] = data; iecs.Send(ndarr, data.CommAddress, ActionRequested.Read); }
internal void makeTree(Iec61850State iecs) { if (treeView1.InvokeRequired) { OnNodeCallback d = new OnNodeCallback(makeTree); this.Invoke(d, new object[] { iecs }); } else { treeView1.ImageList = new ImageList(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Resource1)); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("computer")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("calculator")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("database")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("page_white_text")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("page_white_text_width")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA1")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA2")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA3")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA4")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA5")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("LN6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("FC6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DO6")))); treeView1.ImageList.Images.Add(((System.Drawing.Icon)(resources.GetObject("DA6")))); treeView1.ImageList.Images.Add(((System.Drawing.Image)(resources.GetObject("folder")))); treeView1.Nodes.Clear(); TreeNode n = treeView1.Nodes.Add(iecs.ied.Name + " = " + toolStripComboBox_Hostname.Text + ", Vendor = " + (iecs.ied as NodeIed).VendorName + ", Model = " + (iecs.ied as NodeIed).ModelName + ", Revision = " + (iecs.ied as NodeIed).Revision + ", DefineNVL = " + (iecs.ied as NodeIed).DefineNVL ); NodeBase nb = iecs.ied; n.Tag = nb; n.ImageIndex = 0; foreach (NodeBase b in nb.GetChildNodes()) { TreeNode tn2 = n.Nodes.Add(b.Name); tn2.Tag = b; tn2.ImageIndex = 1; tn2.SelectedImageIndex = 1; TreeNode tn3 = tn2.Nodes.Add("Data"); tn3.Tag = b; tn3.ImageIndex = 2; tn3.SelectedImageIndex = 2; makeTree_dataNode(b, tn3); NodeBase lb = iecs.lists.FindChildNode(b.Name); if (lb != null) { tn3 = tn2.Nodes.Add("DataSets"); tn3.Tag = lb; tn3.ImageIndex = 3; tn3.SelectedImageIndex = 3; makeTree_listNode(lb, tn3); } NodeBase rb = iecs.reports.FindChildNode(b.Name); if (rb != null) { tn3 = tn2.Nodes.Add("Reports"); tn3.Tag = rb; tn3.ImageIndex = 3; tn3.SelectedImageIndex = 3; makeTree_reportNode(rb, tn3); } } nb = iecs.files; TreeNode tn4 = n.Nodes.Add("Files"); tn4.Tag = iecs.files; tn4.ImageIndex = 3; tn4.SelectedImageIndex = 3; makeTree_fileNode(nb, tn4); } }
int recursiveReadData(NodeBase nd, GOOSE_ASN1_Model.Data t, NodeBase ndcn, int id, DateTime captureTime) { int _id = id; if (t == null) { return(-1); } if (t.Array != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.array; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Array_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.array; (nb as NodeGData).DataValue = t.Array; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Binarytime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.array; (nd as NodeGData).DataValue = t.Binarytime; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Binarytime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.binary_time; (nb as NodeGData).DataValue = t.Binarytime; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Bitstring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.bit_string; (nd as NodeGData).DataValue = t.Bitstring.Value; (nd as NodeGData).DataParam = t.Bitstring.TrailBitsCnt; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Bitstring_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.bit_string; (nb as NodeGData).DataValue = t.Bitstring.Value; (nb as NodeGData).DataParam = t.Bitstring.TrailBitsCnt; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.isBooleanSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.boolean; (nd as NodeGData).DataValue = t.Boolean; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Boolean_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.boolean; (nb as NodeGData).DataValue = t.Boolean; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.BooleanArray != null) { return(0); } else if (t.Floatingpoint != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.floating_point; (nd as NodeGData).DataValue = t.Floatingpoint; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Floatingpoint_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.floating_point; (nb as NodeGData).DataValue = t.Floatingpoint; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Generalizedtime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.generalized_time; (nd as NodeGData).DataValue = t.Generalizedtime; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Generalizedtime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.generalized_time; (nb as NodeGData).DataValue = t.Generalizedtime; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.isIntegerSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.integer; (nd as NodeGData).DataValue = t.Integer; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Integer_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.integer; (nb as NodeGData).DataValue = t.Integer; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.MMSString != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.mMSString; (nd as NodeGData).DataValue = t.MMSString; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("MMSString_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.mMSString; (nb as NodeGData).DataValue = t.MMSString; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Octetstring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.octet_string; (nd as NodeGData).DataValue = t.Octetstring; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Octetstring_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.octet_string; (nb as NodeGData).DataValue = t.Octetstring; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Structure != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.structure; NodeBase[] nd1 = nd.GetChildNodes(); int i = 0; int j = 0; foreach (GOOSE_ASN1_Model.Data data in t.Structure.Value) { j = recursiveReadData(nd1[i++], data, null, j, captureTime); } return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Structure_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.structure; NodeBase nb1 = ndcn.AddChildNode(nb); int i = 0; foreach (GOOSE_ASN1_Model.Data data in t.Structure.Value) { i = recursiveReadData(null, data, nb1, i, captureTime); } return(++_id); } else { return(-1); } } else if (t.isUnsignedSelected()) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.unsigned; (nd as NodeGData).DataValue = t.Unsigned; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Unsigned_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.unsigned; (nb as NodeGData).DataValue = t.Unsigned; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Utctime != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.utc_time; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Utctime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.utc_time; ndcn.AddChildNode(nb); return(++_id); } else { return(-1); } } else if (t.Visiblestring != null) { if (nd != null) { (nd as NodeGData).CaptureTime = captureTime; (nd as NodeGData).DataType = scsm_MMS_TypeEnum.visible_string; (nd as NodeGData).DataValue = t.Visiblestring; return(0); } else if (ndcn != null) { NodeBase nb = new NodeGData("Utctime_" + _id.ToString()); (nb as NodeGData).CaptureTime = captureTime; (nb as NodeGData).DataType = scsm_MMS_TypeEnum.visible_string; (nb as NodeGData).DataValue = t.Visiblestring; return(++_id); } else { return(-1); } } else { return(-1); } }
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Button == MouseButtons.Right && e.Node != null) { NodeBase n = (NodeBase)e.Node.Tag; ContextMenuStrip menu = new ContextMenuStrip(); ToolStripItem item; if (n != null) { if (n is NodeVL) { if ((n as NodeVL).Defined) { if ((n as NodeVL).Activated) { item = menu.Items.Add("Deactivate Reports"); item.Tag = n; item.Click += new EventHandler(OnDeactivateNVLClick); } else { item = menu.Items.Add("Activate Reports"); item.Tag = n; item.Click += new EventHandler(OnActivateNVLClick); } } else { item = menu.Items.Add("Send Define Report Request"); item.Tag = n; item.Click += new EventHandler(OnDefineNVLClick); } if ((n as NodeVL).Deletable) { item = menu.Items.Add("Delete Report"); item.Tag = n; item.Click += new EventHandler(OnDeleteNVLClick); } } else if (e.Node.Text == "lists" && n.GetIecs().ied.DefineNVL) { item = menu.Items.Add("Add New Name List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnAddNVLClick); } else if (e.Node.Text == "files") { item = menu.Items.Add("Read File List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileListClick); } if (n is NodeFile && (n as NodeFile).isDir) { item = menu.Items.Add("Read File List"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileListClick); } if (n is NodeFile && !(n as NodeFile).isDir && !(n as NodeFile).FileReady) { item = menu.Items.Add("Get File"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileGetClick); } if (n is NodeFile && !(n as NodeFile).isDir && (n as NodeFile).FileReady) { item = menu.Items.Add("Save File"); item.Tag = n; listsNode = e.Node; item.Click += new EventHandler(OnFileSaveClick); } if (n is NodeData && n.Name == "ctlVal") { item = menu.Items.Add("Send Command (Writes)"); item.Tag = n; item.Click += new EventHandler(OnSendCommandClick); item = menu.Items.Add("Send Command (Structure)"); item.Tag = n; item.Click += new EventHandler(OnSendCommandAsStructureClick); } if (n is NodeData || n is NodeFC) { item = menu.Items.Add("Read Data"); item.Tag = n; item.Click += new EventHandler(OnReadDataClick); } if (n is NodeData && n.GetChildNodes().Length == 0) { item = menu.Items.Add("Write Data"); item.Tag = n; item.Click += new EventHandler(OnWriteDataClick); } } if (menu.Items.Count > 0) { menu.Show((Control)sender, e.Location); } } }
private void WorkerThreadProc(object obj) { Scsm_MMS_Worker self = (Scsm_MMS_Worker)obj; iecs = new Iec61850State(); iecs.hostname = self.isoParameters.hostname; // due to tcps inheritance iecs.port = self.isoParameters.port; // due to tcps inheritance iecs.cp = self.isoParameters; iecs.logger = Logger.getLogger(); _env.winMgr.BindToCapture(iecs); _waitHandles[0] = iecs.connectDone; _waitHandles[1] = iecs.receiveDone; _waitHandles[2] = iecs.sendDone; _waitHandles[3] = new ManualResetEvent(false); // end thread _waitHandles[4] = iecs.sendQueueWritten; //DateTime tout = null; CommAddress ad = new CommAddress(); DateTime IdentifyTimeoutBase = new DateTime(); TimeSpan IdentifyTimeout = new TimeSpan(0, 0, 5); // 5 sec while (self._run) { switch (iecs.tstate) { case TcpProtocolState.TCP_STATE_START: iecs.logger.LogInfo("[TCP_STATE_START]"); iecs.kstate = IsoTpktState.TPKT_RECEIVE_START; iecs.ostate = IsoProtocolState.OSI_STATE_START; iecs.istate = Iec61850lStateEnum.IEC61850_STATE_START; TcpRw.StartClient(iecs); break; case TcpProtocolState.TCP_STATE_SHUTDOWN: iecs.logger.LogInfo("[TCP_STATE_SHUTDOWN]"); Stop(); Thread.Sleep(10000); iecs.tstate = TcpProtocolState.TCP_STATE_START; break; case TcpProtocolState.TCP_CONNECTED: switch (iecs.ostate) { case IsoProtocolState.OSI_CONNECT_COTP: iecs.logger.LogInfo("[OSI_CONNECT_COTP]"); iecs.ostate = IsoProtocolState.OSI_CONNECT_COTP_WAIT; iecs.iso.SendCOTPSessionInit(iecs); break; case IsoProtocolState.OSI_CONNECT_PRES: iecs.logger.LogInfo("[OSI_CONNECT_PRES]"); // This cannot be before Send, but is issued inside Send chain before TCP send // iecs.ostate = IsoProtocolState.OSI_CONNECT_PRES_WAIT; iecs.mms.SendInitiate(iecs); break; case IsoProtocolState.OSI_CONNECTED: switch (iecs.istate) { case Iec61850lStateEnum.IEC61850_STATE_START: if (iecs.DataModel.ied.Identify) { iecs.logger.LogInfo("[IEC61850_STATE_START] (Send IdentifyRequest)"); iecs.istate = Iec61850lStateEnum.IEC61850_CONNECT_MMS_WAIT; iecs.mms.SendIdentify(iecs); IdentifyTimeoutBase = DateTime.UtcNow; } else { iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_DOMAIN; } break; case Iec61850lStateEnum.IEC61850_CONNECT_MMS_WAIT: // If we wait for Identify response too long, continue without it if (DateTime.UtcNow.Subtract(IdentifyTimeout).CompareTo(IdentifyTimeoutBase) > 0) { // Timeout expired iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_DOMAIN; iecs.logger.LogWarning("MMS Identify message not supported by server, although declared in ServicesSupportedCalled bitstring"); } break; case Iec61850lStateEnum.IEC61850_READ_NAMELIST_DOMAIN: iecs.logger.LogDebug("[IEC61850_READ_NAMELIST_DOMAIN]"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_DOMAIN_WAIT; iecs.mms.SendGetNameListDomain(iecs); break; case Iec61850lStateEnum.IEC61850_READ_NAMELIST_VAR: iecs.logger.LogDebug("[IEC61850_READ_NAMELIST_VAR]"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_VAR_WAIT; iecs.mms.SendGetNameListVariables(iecs); break; case Iec61850lStateEnum.IEC61850_READ_ACCESSAT_VAR: iecs.logger.LogDebug("[IEC61850_READ_ACCESSAT_VAR]"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_ACCESSAT_VAR_WAIT; iecs.mms.SendGetVariableAccessAttributes(iecs); break; case Iec61850lStateEnum.IEC61850_READ_MODEL_DATA: if (_env.dataReadOnStartup) { iecs.logger.LogDebug("[IEC61850_READ_MODEL_DATA]"); CommAddress adr = new CommAddress(); adr.Domain = null; adr.Variable = null; adr.owner = null; NodeBase[] data = new NodeBase[1]; // Issue reads by FC level data[0] = iecs.DataModel.ied.GetActualChildNode().GetActualChildNode().GetActualChildNode(); WriteQueueElement wqel = new WriteQueueElement(data, adr, ActionRequested.Read); iecs.istate = Iec61850lStateEnum.IEC61850_READ_MODEL_DATA_WAIT; iecs.mms.SendRead(iecs, wqel); } else { iecs.logger.LogDebug("[IEC61850_READ_MODEL_DATA] - Skipped due to a presetting"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_NAMED_VARIABLE_LIST; } break; case Iec61850lStateEnum.IEC61850_READ_NAMELIST_NAMED_VARIABLE_LIST: iecs.logger.LogDebug("[IEC61850_READ_NAMELIST_NAMED_VARIABLE_LIST]"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_NAMELIST_NAMED_VARIABLE_LIST_WAIT; iecs.mms.SendGetNameListNamedVariableList(iecs); break; case Iec61850lStateEnum.IEC61850_READ_ACCESSAT_NAMED_VARIABLE_LIST: iecs.logger.LogDebug("[IEC61850_READ_ACCESSAT_NAMED_VARIABLE_LIST]"); iecs.istate = Iec61850lStateEnum.IEC61850_READ_ACCESSAT_NAMED_VARIABLE_LIST_WAIT; if (iecs.mms.SendGetNamedVariableListAttributes(iecs) != 0) { // No VarLists iecs.logger.LogInfo("Init end: [IEC61850_FREILAUF]"); iecs.istate = Iec61850lStateEnum.IEC61850_MAKEGUI; } break; case Iec61850lStateEnum.IEC61850_MAKEGUI: iecs.logger.LogDebug("[IEC61850_MAKEGUI]"); iecs.DataModel.BuildIECModelFromMMSModel(); self._env.winMgr.MakeIedTree(iecs); self._env.winMgr.MakeIecTree(iecs); self._env.winMgr.mainWindow.Set_iecf(iecs); iecs.istate = Iec61850lStateEnum.IEC61850_FREILAUF; break; case Iec61850lStateEnum.IEC61850_FREILAUF: // File service handling switch (iecs.fstate) { case FileTransferState.FILE_DIRECTORY: if (iecs.lastFileOperationData[0] is NodeIed) { self._env.winMgr.MakeFileTree(iecs); } iecs.fstate = FileTransferState.FILE_NO_ACTION; break; case FileTransferState.FILE_OPENED: case FileTransferState.FILE_READ: // issue a read iecs.Send(iecs.lastFileOperationData, ad, ActionRequested.ReadFile); iecs.fstate = FileTransferState.FILE_NO_ACTION; break; case FileTransferState.FILE_COMPLETE: // issue a close // file can be saved from context menu iecs.Send(iecs.lastFileOperationData, ad, ActionRequested.CloseFile); iecs.fstate = FileTransferState.FILE_NO_ACTION; break; } break; } break; case IsoProtocolState.OSI_STATE_SHUTDOWN: TcpRw.StopClient(iecs); break; } break; default: break; } int waitres = WaitHandle.WaitAny(_waitHandles, 500); switch (waitres) { case 0: // connect if (iecs.ostate == IsoProtocolState.OSI_STATE_START) { iecs.ostate = IsoProtocolState.OSI_CONNECT_COTP; } iecs.connectDone.Reset(); TcpRw.Receive(iecs); // issue a Receive call break; case 1: // receive iecs.receiveDone.Reset(); TcpRw.Receive(iecs); // issue a new Receive call break; case 2: // send iecs.sendDone.Reset(); break; case 3: // endthread self._run = false; break; case 4: // send data iecs.sendQueueWritten.Reset(); Logger.getLogger().LogDebug("SendQueue Waiting for lock in Worker!"); WriteQueueElement el; while (iecs.SendQueue.TryDequeue(out el)) { switch (el.Action) { case ActionRequested.Write: iecs.mms.SendWrite(iecs, el); break; case ActionRequested.WriteAsStructure: iecs.mms.SendWriteAsStructure(iecs, el); break; case ActionRequested.Read: if (el.Data[0] is NodeVL) { iecs.mms.SendReadVL(iecs, el); } else { iecs.mms.SendRead(iecs, el); } break; case ActionRequested.DefineNVL: iecs.mms.SendDefineNVL(iecs, el); break; case ActionRequested.DeleteNVL: iecs.mms.SendDeleteNVL(iecs, el); break; case ActionRequested.GetDirectory: iecs.mms.SendFileDirectory(iecs, el); break; case ActionRequested.OpenFile: iecs.mms.SendFileOpen(iecs, el); break; case ActionRequested.ReadFile: iecs.mms.SendFileRead(iecs, el); break; case ActionRequested.CloseFile: iecs.mms.SendFileClose(iecs, el); break; case ActionRequested.FileDelete: iecs.mms.SendFileDelete(iecs, el); break; } } break; case WaitHandle.WaitTimeout: break; } } TcpRw.StopClient(iecs); _env.winMgr.UnBindFromCapture(iecs); if (restart_allowed) { restart_allowed = false; try { _env.winMgr.mainWindow.BeginInvoke((Action) delegate { _env.winMgr.mainWindow.Restart(); }); } catch { } } }
public NodeData[] getWriteArray() { List <NodeData> nlst = new List <NodeData>(); // Reservation - Must go first!!! NodeBase fcn = self.FindChildNode("Resv"); if (sendResv && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("ResvTms"); if (sendResvTms && fcn != null) { nlst.Add((NodeData)fcn); } // Normal members fcn = self.FindChildNode("RptID"); if (sendRptID && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("DatSet"); if (sendDatSet && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("OptFlds"); if (sendOptFlds && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("BufTm"); if (sendBufTm && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("TrgOps"); if (sendTrgOps && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("IntgPd"); if (sendIntgPd && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("PurgeBuf"); if (sendPurgeBuf && fcn != null) { nlst.Add((NodeData)fcn); } fcn = self.FindChildNode("EntryID"); if (sendEntryID && fcn != null) { nlst.Add((NodeData)fcn); } // Activation - Must go last!!! fcn = self.FindChildNode("RptEna"); if (sendRptEna && fcn != null) { nlst.Add((NodeData)fcn); } // GI - Must go after activation!!! fcn = self.FindChildNode("GI"); if (sendGI && fcn != null) { nlst.Add((NodeData)fcn); } return(nlst.ToArray()); }