-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added PUT functionality to MTConnectHttpServer to accept adding observations through the URL query string - Added an ShdrMTConnectHttpServer class in the MTConnect.NET-SHDR project to implement SHDR lines sent as Query parameters - Updated the default MTConnectHttpServer to use the ShdrMTConnectHttpServer class in the MTConnect-Agent-Http application
- Loading branch information
1 parent
28e8afa
commit 310fec4
Showing
6 changed files
with
207 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3371,6 +3371,5 @@ private void DeviceMetricsUpdated(object sender, DeviceMetrics deviceMetrics) | |
} | ||
|
||
#endregion | ||
|
||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/MTConnect.NET-HTTP/Http/MTConnectHttpObservationInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2022 TrakHound Inc., All Rights Reserved. | ||
|
||
// This file is subject to the terms and conditions defined in | ||
// file 'LICENSE.txt', which is part of this source code package. | ||
|
||
namespace MTConnect.Http | ||
{ | ||
/// <summary> | ||
/// An Observation that is attempting to be added to an MTConnect Agent from an Http interface | ||
/// </summary> | ||
public struct MTConnectHttpObservationInput | ||
{ | ||
public string DeviceUuid { get; set; } | ||
|
||
public string DataItemKey { get; set; } | ||
|
||
public string Input { get; set; } | ||
|
||
|
||
public MTConnectHttpObservationInput(string deviceUuid, string dataItemKey, string input) | ||
{ | ||
DeviceUuid = deviceUuid; | ||
DataItemKey = dataItemKey; | ||
Input = input; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) 2022 TrakHound Inc., All Rights Reserved. | ||
|
||
// This file is subject to the terms and conditions defined in | ||
// file 'LICENSE.txt', which is part of this source code package. | ||
|
||
using MTConnect.Adapters.Shdr; | ||
using MTConnect.Agents; | ||
using MTConnect.Devices; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace MTConnect.Http | ||
{ | ||
/// <summary> | ||
/// An Http Web Server for processing MTConnect REST Api Requests with a processor PUT requests for SHDR data sent in the URL query string | ||
/// </summary> | ||
public class ShdrMTConnectHttpServer : MTConnectHttpServer | ||
{ | ||
private readonly IMTConnectAgent _mtconnectAgent; | ||
|
||
|
||
public ShdrMTConnectHttpServer(IMTConnectAgent mtconnectAgent, IEnumerable<string> prefixes = null) : base(mtconnectAgent, prefixes) | ||
{ | ||
_mtconnectAgent = mtconnectAgent; | ||
} | ||
|
||
|
||
protected override async Task<bool> OnObservationInput(string deviceKey, string dataItemKey, string input) | ||
{ | ||
// Get the Devices Document from the Agent | ||
var devicesDocument = await _mtconnectAgent.GetDevicesAsync(deviceKey); | ||
if (devicesDocument != null && !devicesDocument.Devices.IsNullOrEmpty()) | ||
{ | ||
// Get the first Device (should only be one Device) | ||
var device = devicesDocument.Devices.FirstOrDefault(); | ||
if (device != null) | ||
{ | ||
// Get the DataItem based on the Key | ||
var dataItem = device.GetDataItemByKey(dataItemKey); | ||
if (dataItem != null) | ||
{ | ||
// Construct an SHDR Line using the DataItemId and the Input string from Http | ||
var shdrLine = $"{dataItem.Id}|{input}"; | ||
|
||
if (dataItem.Category == DataItemCategory.CONDITION) | ||
{ | ||
var condition = ShdrFaultState.FromString(shdrLine); | ||
if (condition != null) await _mtconnectAgent.AddObservationAsync(device.Uuid, condition); | ||
} | ||
else if (dataItem.Type == Devices.DataItems.Events.MessageDataItem.TypeId) | ||
{ | ||
var message = ShdrMessage.FromString(shdrLine); | ||
if (message != null) await _mtconnectAgent.AddObservationAsync(device.Uuid, message); | ||
} | ||
else if (dataItem.Representation == DataItemRepresentation.TABLE) | ||
{ | ||
var table = ShdrTable.FromString(shdrLine); | ||
if (table != null) await _mtconnectAgent.AddObservationAsync(device.Uuid, table); | ||
} | ||
else if (dataItem.Representation == DataItemRepresentation.DATA_SET) | ||
{ | ||
var dataSet = ShdrDataSet.FromString(shdrLine); | ||
if (dataSet != null) await _mtconnectAgent.AddObservationAsync(device.Uuid, dataSet); | ||
} | ||
else if (dataItem.Representation == DataItemRepresentation.TIME_SERIES) | ||
{ | ||
var timeSeries = ShdrTimeSeries.FromString(shdrLine); | ||
if (timeSeries != null) await _mtconnectAgent.AddObservationAsync(device.Uuid, timeSeries); | ||
} | ||
else | ||
{ | ||
var dataItems = ShdrDataItem.FromString(shdrLine); | ||
if (!dataItems.IsNullOrEmpty()) await _mtconnectAgent.AddObservationsAsync(device.Uuid, dataItems); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters