Skip to content

Commit

Permalink
Updated for MTConnect v2.2
Browse files Browse the repository at this point in the history
- Added 2.2 DataItems & Components
- Added support for Device and Asset Hash property (this replaces the MD5 ChangeId property previously used)
- Added ImageFile configuration
- Added ComponentConfigurationParameters Asset
- Fixed a few minor issues found during updating
  • Loading branch information
PatrickRitchie committed Jul 25, 2023
1 parent 0099cc5 commit 4b07b66
Show file tree
Hide file tree
Showing 57 changed files with 1,510 additions and 181 deletions.
9 changes: 8 additions & 1 deletion src/MTConnect.NET-Common/Agents/MTConnectAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ protected void InitializeAgentDevice(bool initializeDataItems = true)
{
_agent = new Agent(this);
_agent.InitializeDataItems();
_agent.Hash = _agent.GenerateHash();

// Add Name and UUID to DeviceKey dictionary
_deviceKeys.TryRemove(_agent.Name.ToLower(), out _);
Expand Down Expand Up @@ -947,6 +948,9 @@ private Device NormalizeDevice(IDevice device)
}
}
}

// Generate Device Hash
obj.Hash = obj.GenerateHash();

return obj;
}
Expand Down Expand Up @@ -1191,7 +1195,7 @@ public bool AddDevice(IDevice device, bool initializeDataItems = true)
_devices.TryGetValue(obj.Uuid, out var existingDevice);

// Check if Device Already Exists in the Device Buffer and is changed
if (existingDevice != null && obj.ChangeId == existingDevice.ChangeId)
if (existingDevice != null && obj.Hash == existingDevice.Hash)
{
return true;
}
Expand Down Expand Up @@ -1699,6 +1703,9 @@ public bool AddAsset(string deviceKey, IAsset asset, bool? ignoreTimestamp = nul
}
else asset.Timestamp = asset.Timestamp > 0 ? asset.Timestamp : UnixDateTime.Now;

// Set Asset Hash
asset.Hash = asset.GenerateHash();

// Validate Asset based on Device's MTConnectVersion
var validationResults = asset.IsValid(device.MTConnectVersion);
if (validationResults.IsValid || _configuration.InputValidationLevel < InputValidationLevel.Strict)
Expand Down
38 changes: 28 additions & 10 deletions src/MTConnect.NET-Common/Assets/Asset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

namespace MTConnect.Assets
{
/// <summary>
/// It is used in the manufacturing process, but is not permanently associated with a single piece of equipment.
/// It can be removed from the piece of equipment without compromising its function, and can be associated with other pieces of equipment during its lifecycle.
/// </summary>
public class Asset : IAsset
/// <summary>
/// It is used in the manufacturing process, but is not permanently associated with a single piece of equipment.
/// It can be removed from the piece of equipment without compromising its function, and can be associated with other pieces of equipment during its lifecycle.
/// </summary>
public class Asset : IAsset
{
private static Dictionary<string, Type> _types;

Expand Down Expand Up @@ -105,6 +105,12 @@ public DateTime DateTime
[JsonPropertyName("description")]
public string Description { get; set; }

/// <summary>
/// Condensed message digest from a secure one-way hash function. FIPS PUB 180-4
/// </summary>
[XmlAttribute("hash")]
[JsonPropertyName("hash")]
public string Hash { get; set; }

public static IAsset Create(string type)
{
Expand Down Expand Up @@ -186,16 +192,28 @@ private static Dictionary<string, Type> GetAllTypes()
}


public virtual IAsset Process(Version mtconnectVersion)
public IAsset Process(Version mtconnectVersion)
{
if (mtconnectVersion < MTConnectVersions.Version12) return null;
if (mtconnectVersion < MTConnectVersions.Version12) return null;

return this;
}
if (mtconnectVersion < MTConnectVersions.Version22) Hash = null;

return OnProcess(mtconnectVersion);
}

protected virtual IAsset OnProcess(Version mtconnectVersion)
{
return this;
}

public virtual AssetValidationResult IsValid(Version mtconnectVersion)
{
return new AssetValidationResult(true);
}
}

public virtual string GenerateHash()
{
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

namespace MTConnect.Assets.ComponentConfigurationParameters
{
/// <summary>
/// Set of parameters that govern the functionality of the related Component
/// </summary>
[XmlRoot("ComponentConfigurationParameters")]
public class ComponentConfigurationParametersAsset : Asset
{
public const string TypeId = "ComponentConfigurationParameters";


/// <summary>
/// Destinations organizes one or more Destination elements.
/// </summary>
[XmlArray("ParameterSets")]
[XmlArrayItem("ParameterSet", typeof(ParameterSet))]
[JsonPropertyName("parameterSets")]
public List<ParameterSet> ParameterSets { get; set; }

[XmlIgnore]
public bool ParameterSetsSpecified => !ParameterSets.IsNullOrEmpty();


public ComponentConfigurationParametersAsset()
{
Type = TypeId;
}


protected override IAsset OnProcess(Version mtconnectVersion)
{
if (mtconnectVersion != null && mtconnectVersion >= MTConnectVersions.Version22)
{
return this;
}

return null;
}

public override AssetValidationResult IsValid(Version mtconnectVersion)
{
var message = "";
var result = true;

if (ParameterSets.IsNullOrEmpty())
{
message = "At least one ParameterSet is Required";
result = false;
}

return new AssetValidationResult(result, message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;

namespace MTConnect.Assets.ComponentConfigurationParameters
{
/// <summary>
/// Property defining a configuration of a Component
/// </summary>
public class Parameter
{
/// <summary>
/// Internal identifier, register, or address.
/// </summary>
[XmlAttribute("identifier")]
[JsonPropertyName("identifier")]
public string Identifier { get; set; }

/// <summary>
/// Descriptive name.
/// </summary>
[XmlAttribute("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// Minimal allowed value.
/// </summary>
[XmlAttribute("minimum")]
[JsonPropertyName("minimum")]
public string Minimum { get; set; }

/// <summary>
/// Maximum allowed value.
/// </summary>
[XmlAttribute("maximum")]
[JsonPropertyName("maximum")]
public string Maximum { get; set; }

/// <summary>
/// Nominal value.
/// </summary>
[XmlAttribute("nominal")]
[JsonPropertyName("nominal")]
public string Nominal { get; set; }

/// <summary>
/// Configured value.
/// </summary>
[XmlAttribute("value")]
[JsonPropertyName("value")]
public string Value { get; set; }

/// <summary>
/// Engineering units. Units SHOULD be SI or MTConnect Units(See UnitEnum).
/// </summary>
[XmlAttribute("units")]
[JsonPropertyName("units")]
public string Units { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;

namespace MTConnect.Assets.ComponentConfigurationParameters
{
/// <summary>
/// Set of parameters defining the configuration of a Component
/// </summary>
public class ParameterSet
{
/// <summary>
/// Set of parameters defining the configuration of a Component
/// </summary>
[XmlAttribute("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

/// <summary>
/// Destinations organizes one or more Destination elements.
/// </summary>
[XmlArray("Parameters")]
[XmlArrayItem("Parameter", typeof(Parameter))]
[JsonPropertyName("parameters")]
public List<ParameterSet> Parameters { get; set; }

[XmlIgnore]
public bool ParametersSpecified => !Parameters.IsNullOrEmpty();
}
}
30 changes: 27 additions & 3 deletions src/MTConnect.NET-Common/Assets/CuttingTools/CuttingToolAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;

namespace MTConnect.Assets.CuttingTools
{
[XmlRoot("CuttingTool")]
[XmlRoot("CuttingTool")]
public class CuttingToolAsset : Asset
{
public const string TypeId = "CuttingTool";
Expand Down Expand Up @@ -62,7 +63,7 @@ public CuttingToolAsset()
}


public override IAsset Process(Version mtconnectVersion)
protected override IAsset OnProcess(Version mtconnectVersion)
{
if (mtconnectVersion != null && mtconnectVersion >= MTConnectVersions.Version12)
{
Expand All @@ -74,6 +75,7 @@ public override IAsset Process(Version mtconnectVersion)
if (mtconnectVersion > MTConnectVersions.Version13) asset.DeviceUuid = DeviceUuid;
asset.Removed = Removed;
asset.Description = Description;
asset.Hash = Hash;

if (!string.IsNullOrEmpty(SerialNumber)) asset.SerialNumber = SerialNumber;
else asset.SerialNumber = AssetId;
Expand Down Expand Up @@ -107,5 +109,27 @@ public override AssetValidationResult IsValid(Version mtconnectVersion)

return new AssetValidationResult(result, message);
}
}


public override string GenerateHash()
{
return GenerateHash(this);
}

public static string GenerateHash(CuttingToolAsset asset)
{
if (asset != null)
{
var ids = new List<string>();

ids.Add(ObjectExtensions.GetHashPropertyString(asset).ToSHA1Hash());

// Need to include CuttingItems

return StringFunctions.ToSHA1Hash(ids.ToArray());
}

return null;
}
}
}
12 changes: 6 additions & 6 deletions src/MTConnect.NET-Common/Assets/Files/AbstractFileAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

namespace MTConnect.Assets.Files
{
/// <summary>
/// An AbstractFile is an abstract Asset type model that contains the common properties of the File and FileArchetype types.
/// </summary>
[XmlRoot("AbstractFile")]
/// <summary>
/// An AbstractFile is an abstract Asset type model that contains the common properties of the File and FileArchetype types.
/// </summary>
[XmlRoot("AbstractFile")]
public abstract class AbstractFileAsset<T> : Asset where T : IAsset
{
/// <summary>
Expand Down Expand Up @@ -68,7 +68,7 @@ public abstract class AbstractFileAsset<T> : Asset where T : IAsset
public bool FileCommentsSpecified => !FileComments.IsNullOrEmpty();


public override IAsset Process(Version mtconnectVersion)
protected override IAsset OnProcess(Version mtconnectVersion)
{
if (mtconnectVersion != null && mtconnectVersion >= MTConnectVersions.Version17)
{
Expand Down Expand Up @@ -96,5 +96,5 @@ public override AssetValidationResult IsValid(Version mtconnectVersion)

return new AssetValidationResult(result, message);
}
}
}
}
Loading

0 comments on commit 4b07b66

Please sign in to comment.