Skip to content

Commit

Permalink
update to AASxPluginAssetInterfacesDesc project to reflect what is in…
Browse files Browse the repository at this point in the history
… specification (#256)
  • Loading branch information
Kaz040 authored Feb 27, 2025
1 parent 610e41c commit f9f11d3
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/AasxPackageExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxPluginProductChangeNoti
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxPluginSmdExporter", "AasxPluginSmdExporter\AasxPluginSmdExporter.csproj", "{621D9B9C-1723-48CB-AE2D-3C17390B7F4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AasxOpcUa2Client", "AasxOpcUa2Client\AasxOpcUa2Client.csproj", "{6B8BDF03-9C9B-492B-8904-9756B498B9B7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxOpcUa2Client", "AasxOpcUa2Client\AasxOpcUa2Client.csproj", "{6B8BDF03-9C9B-492B-8904-9756B498B9B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
122 changes: 101 additions & 21 deletions src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This source code may use other Open Source software components (see LICENSE.txt)
using System.Windows.Media.Animation;
using AasxIntegrationBase.AdminShellEvents;
using System.IO;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace AasxPluginAssetInterfaceDescription
{
Expand Down Expand Up @@ -68,6 +70,11 @@ public class AidIfxItemStatus
/// </summary>
public CD_Forms FormData = null;

/// <summary>
/// To help map object payloads(JSON, XML or Octet-stream that is complex)
/// </summary>
public string payloadType = null;

/// <summary>
/// String data for value incl. unit information.
/// </summary>
Expand Down Expand Up @@ -121,6 +128,17 @@ public class AidInterfaceStatus
/// </summary>
public string EndpointBase = "";


/// <summary>
/// Used by byteStream payload for decoding, presently, mainly used by Modbus but other protocols will also be using it
/// </summary>
public string mostSignificantByte = "";

/// <summary>
/// Used by byteStream payload for decoding, presently, mainly used by Modbus but other protocols will also be using it
/// </summary>
public string mostSignificantWord = "";

/// <summary>
/// Actual summary of the status of the interface.
/// </summary>
Expand Down Expand Up @@ -239,6 +257,16 @@ public class AidBaseConnection
/// </summary>
public string Password = null;

/// <summary>
/// Used by byteStream payload for decoding, presently, mainly used by Modbus but other protocols will also be using it
/// </summary>
public string mostSignificantByte = "";

/// <summary>
/// Used by byteStream payload for decoding, presently, mainly used by Modbus but other protocols will also be using it
/// </summary>
public string mostSignificantWord = "";

/// <summary>
/// If greater 10, specifies the time rate in milli seconds for polling the
/// respective subscriptions.
Expand Down Expand Up @@ -310,27 +338,70 @@ public void NotifyOutputItems(AidIfxItemStatus item, string strval)
foreach (var moi in item.MapOutputItems)
{
// valid?
if (moi?.MapRelation?.Second == null
|| !(moi.MapRelation.SecondHint is Aas.Property prop))
if (moi?.MapRelation?.Second == null)
continue;

// set here
prop.Value = strval;
// For literal payloads
else if (moi.MapRelation.SecondHint is Aas.Property prop)
{
// set here
prop.Value = strval;

// create
var evi = new AasPayloadUpdateValueItem(
path: (prop)?.GetModelReference()?.Keys,
value: prop.ValueAsText());

// create
var evi = new AasPayloadUpdateValueItem(
path: (prop)?.GetModelReference()?.Keys,
value: prop.ValueAsText());
evi.ValueId = prop.ValueId;

evi.ValueId = prop.ValueId;
evi.FoundReferable = prop;

evi.FoundReferable = prop;
// add to the aas element itself
DiaryDataDef.AddAndSetTimestamps(prop, evi, isCreate: false);

// add to the aas element itself
DiaryDataDef.AddAndSetTimestamps(prop, evi, isCreate: false);
// give upwards for animation
AnimateSingleValueChange?.Invoke(prop);
}

// for object payloads--only JSON for now.
else if (moi.MapRelation.SecondHint is Aas.SubmodelElementCollection coll)
{
//run complex mappping here

JObject payloadJObject;

using (var tdStringReader = new StringReader(strval))
using (var jsonTextReader = new JsonTextReader(tdStringReader)
{ DateParseHandling = DateParseHandling.None })
{
payloadJObject = JObject.FromObject(JToken.ReadFrom(jsonTextReader));
}
foreach (var internalProperty in coll.Value)
{
if ((internalProperty is Aas.Property internalProp) && payloadJObject.ContainsKey(internalProperty.IdShort))
{
// set The value related to the json key found here
internalProp.Value = payloadJObject[internalProperty.IdShort].ToString();

// create
var evi = new AasPayloadUpdateValueItem(
path: (internalProp)?.GetModelReference()?.Keys,
value: internalProp.ValueAsText());

// give upwards for animation
AnimateSingleValueChange?.Invoke(prop);
evi.ValueId = internalProp.ValueId;

evi.FoundReferable = internalProp;

// add to the aas element itself
DiaryDataDef.AddAndSetTimestamps(internalProp, evi, isCreate: false);

// give upwards for animation
AnimateSingleValueChange?.Invoke(internalProp);
}
}
}


}
}
}
Expand Down Expand Up @@ -762,6 +833,8 @@ public void PrepareAidInformation(Aas.ISubmodel smAid, Aas.ISubmodel smMapping =
DisplayName = $"{dn}",
Info = $"{ifx.EndpointMetadata?.Base}",
EndpointBase = "" + ifx.EndpointMetadata?.Base,
mostSignificantByte = "" + ifx.EndpointMetadata?.Modv_mostSignificantByte,
mostSignificantWord = "" + ifx.EndpointMetadata?.Modv_mostSignificantWord,
Tag = ifx
};
InterfaceStatus.Add(aidIfx);
Expand All @@ -780,7 +853,7 @@ public void PrepareAidInformation(Aas.ISubmodel smAid, Aas.ISubmodel smMapping =
FormData = propName.Forms,
Value = "???"
};
aidIfx.AddItem(ifcItem);


// does (some) mapping have a source with this property name?
var lst = new List<AidMappingOutputItem>();
Expand All @@ -797,19 +870,26 @@ public void PrepareAidInformation(Aas.ISubmodel smAid, Aas.ISubmodel smMapping =
MapRelation = mr
});
if (lst.Count > 0)
{
aidIfx.AddItem(ifcItem);
ifcItem.MapOutputItems = lst;
}


// directly recurse?
/*
if (propName?.Properties?.Property != null)
foreach (var child in propName.Properties.Property)
{
//added this to cater for internal object mapping.
child.Forms = propName.Forms;
recurseProp(location + " . " + ifcItem.DisplayName, child);
*/
}

};

if (ifx.InterfaceMetadata?.Properties?.Property == null)
if (ifx.InteractionMetadata?.Properties?.Property == null)
continue;
foreach (var propName in ifx.InterfaceMetadata?.Properties?.Property)
foreach (var propName in ifx.InteractionMetadata?.Properties?.Property)
recurseProp("\u2302", propName);
}
}
Expand Down Expand Up @@ -869,12 +949,12 @@ public void SetAidInformationForUpdateAndTimeout(
// polltimes
SetDoubleOnDefaultOrAvgOfIntList(
ref ifc.UpdateFreqMs, 10.0, defaultUpdateFreqMs,
SelectValuesToIntList(ifc?.Items?.Values, (it) => it.FormData?.Modbus_pollingTime));
SelectValuesToIntList(ifc?.Items?.Values, (it) => it.FormData?.Modv_pollingTime));

// time out
SetDoubleOnDefaultOrAvgOfIntList(
ref ifc.TimeOutMs, 10.0, defaultTimeOutMs,
SelectValuesToIntList(ifc?.Items?.Values, (it) => it.FormData?.Modbus_timeout));
SelectValuesToIntList(ifc?.Items?.Values, (it) => it.FormData?.Modv_timeout));
}

// for OPC UA, analyze update frequency and timeout
Expand Down
Loading

0 comments on commit f9f11d3

Please sign in to comment.