Skip to content

Commit

Permalink
Bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
barnstee committed Nov 9, 2023
1 parent fd631e4 commit ee8d609
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 72 deletions.
113 changes: 59 additions & 54 deletions src/OPCUAViewer/SimpleNodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace AdminShell
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

public class SimpleNodeManager : CustomNodeManager2
Expand Down Expand Up @@ -63,72 +64,76 @@ public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> e
}
}

AssetDescriptionFileDataType product = new();
string json = System.IO.File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "product_carbon_footprint.json"));
using (var decoder = new JsonDecoder(json, Server.MessageContext))
// load our node instances and values for the I4AAS namespace from the PCF file
if (NamespaceUris.Contains("http://opcfoundation.org/UA/I4AAS/"))
{
product.Namespaces = decoder.ReadStringArray(nameof(product.Namespaces));
}

ServiceMessageContext context = new ServiceMessageContext();
product.Namespaces.ForEach(x => context.NamespaceUris.Append(x));
context.Factory = Server.Factory;

using (var decoder = new JsonDecoder(json, context))
{
product.Decode(decoder);
}

var node = new AssetModelState(null);
AssetDescriptionFileDataType product = new();
string json = System.IO.File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "product_carbon_footprint.json"));
using (var decoder = new JsonDecoder(json, Server.MessageContext))
{
product.Namespaces = decoder.ReadStringArray(nameof(product.Namespaces));
}

node.Create(
SystemContext,
new NodeId(product.ModelIdShort, NamespaceIndexes[0]),
new QualifiedName(product.ModelIdShort, NamespaceIndexes[0]),
null,
true);
ServiceMessageContext context = new ServiceMessageContext();
product.Namespaces.ForEach(x => context.NamespaceUris.Append(x));
context.Factory = Server.Factory;

foreach (var submodel in product.Submodels)
{
if (submodel.Body is NameplateSubmodelDataType nameplate)
using (var decoder = new JsonDecoder(json, context))
{
InitializeChildFromData(nameplate, node.Nameplate);
continue;
product.Decode(decoder);
}

if (submodel.Body is SubmodelDataType instance)
var node = new AssetModelState(null);

node.Create(
SystemContext,
new NodeId(product.ModelIdShort, NamespaceIndexes[0]),
new QualifiedName(product.ModelIdShort, NamespaceIndexes[0]),
null,
true);

foreach (var submodel in product.Submodels)
{
SubmodelState child;
if (submodel.Body is NameplateSubmodelDataType nameplate)
{
InitializeChildFromData(nameplate, node.Nameplate);
continue;
}

switch (instance)
if (submodel.Body is SubmodelDataType instance)
{
case ProductCarbonFootprintDataType:
child = new ProductCarbonFootprintSubmodelState(node);
break;
default:
child = new SubmodelState(node);
break;
};

child.Create(
SystemContext,
new NodeId(instance.ModelIdShort, NamespaceIndexes[0]),
new QualifiedName(instance.ModelIdShort, NamespaceIndexes[0]),
null,
true);

node.AddChild(child);

InitializeChildFromData(instance, child);
continue;
SubmodelState child;

switch (instance)
{
case ProductCarbonFootprintDataType:
child = new ProductCarbonFootprintSubmodelState(node);
break;
default:
child = new SubmodelState(node);
break;
};

child.Create(
SystemContext,
new NodeId(instance.ModelIdShort, NamespaceIndexes[0]),
new QualifiedName(instance.ModelIdShort, NamespaceIndexes[0]),
null,
true);

node.AddChild(child);

InitializeChildFromData(instance, child);
continue;
}
}
}

// store it and all of its children in the pre-defined nodes dictionary for easy look up.
AddPredefinedNode(SystemContext, node);
// store it and all of its children in the pre-defined nodes dictionary for easy look up.
AddPredefinedNode(SystemContext, node);

// link root to objects folder.
references.Add(new NodeStateReference(Opc.Ua.ReferenceTypeIds.Organizes, false, node.NodeId));
// link root to objects folder.
references.Add(new NodeStateReference(Opc.Ua.ReferenceTypeIds.Organizes, false, node.NodeId));
}
}

AddReverseReferences(externalReferences);
Expand Down
37 changes: 28 additions & 9 deletions src/OPCUAViewer/UANodesetViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class UANodesetViewer

private Dictionary<string, ApplicationInstance> _applications = new();

private bool _isRunning = false;
private Dictionary<string, bool> _isRunning = new();

private string _instanceUrl = string.Empty;

Expand All @@ -32,7 +32,14 @@ public class UANodesetViewer

public void Login(string instanceUrl, string clientId, string secret, string key)
{
if (!_isRunning
_nodeSetFilenames.Clear();

if (!_isRunning.ContainsKey(key))
{
_isRunning.Add(key, false);
}

if (!_isRunning[key]
&& !string.IsNullOrEmpty(clientId)
&& !string.IsNullOrEmpty(secret)
&& !string.IsNullOrEmpty(instanceUrl)
Expand Down Expand Up @@ -75,20 +82,32 @@ public void Login(string instanceUrl, string clientId, string secret, string key
// start the UA server
StartServerAsync(key).GetAwaiter().GetResult();

_isRunning = true;
_isRunning[key] = true;
}
}

public void LoadLocalNodesetFile(string name, string key)
{
// fix the path to the local nodeset directory and add
string path = Path.Combine(Directory.GetCurrentDirectory(), "NodeSets", name.Substring(name.LastIndexOf('/') + 1));
_nodeSetFilenames.Add(path);
_nodeSetFilenames.Clear();

ValidateNamespacesAndModels(true);
if (!_isRunning.ContainsKey(key))
{
_isRunning.Add(key, false);
}

// start the UA server
StartServerAsync(key).GetAwaiter().GetResult();
if (!_isRunning[key])
{
// fix the path to the local nodeset directory and add
string path = Path.Combine(Directory.GetCurrentDirectory(), "NodeSets", name.Substring(name.LastIndexOf('/') + 1));
_nodeSetFilenames.Add(path);

ValidateNamespacesAndModels(true);

// start the UA server
StartServerAsync(key).GetAwaiter().GetResult();

_isRunning[key] = true;
}
}

private string ValidateNamespacesAndModels(bool autodownloadreferences)
Expand Down
32 changes: 23 additions & 9 deletions src/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,29 @@
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"environmentVariables": {
"ServicePassword": "",
"UACLUsername": "",
"UACLPassword": "",
"ADX_HOST": "",
"ADX_DB": "",
"AAD_TENANT": "",
"AAD_APPLICATION_ID": "",
"AAD_APPLICATION_KEY": "",
"ADX_QUERY_INTERVAL":""
//"ServicePassword": "",
//"UACLUsername": "[email protected]",
//"UACLPassword": "EMoerike11!!",
//"ADX_HOST": "",
//"ADX_DB": "",
//"AAD_TENANT": "6e660ce4-d51a-4585-80c6-58035e212354",
//"AAD_APPLICATION_ID": "da43d633-f342-4607-afe8-c02ebec17835",
//"AAD_APPLICATION_KEY": "XXs8Q~5Gm-gamhs2NC1i4tUlGiG83o7mIJsbXbdF",
//"ADX_QUERY_INTERVAL": "",
//"OPCUA_REPORTING": "1",
//"CALCULATE_PCF_SMIP": "1",
//"USE_JSON_SERIALIZATION": "1",
//"WATTTIME_USER": "erichb",
//"WATTTIME_PASSWORD": "EMoerike22!!",
//"HostingPlatform": "Azure",
//"BlobStorageConnectionString": "",
//"SMIP_GRAPHQL_ENDPOINT_URL": "https://demo.cesmii.net/graphql",
//"SMIP_USERNAME": "Barnstedt",
//"SMIP_CLIENT_ID": "aasrepo",
//"SMIP_CLIENT_PASSWORD": "EMoerike22",
//"SMIP_CLIENT_ROLE": "demo_group",
//"SMIP_BEARER_TOKEN": "",
//"DATA_QUERY_INTERVAL": "60000"
}
}
}
Expand Down

0 comments on commit ee8d609

Please sign in to comment.