Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
* investigate dll error for MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
festo-i40 committed Jan 7, 2024
1 parent 634c99d commit 8d97e2f
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 34 deletions.
23 changes: 23 additions & 0 deletions src/AasxIntegrationBase/LogInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ public StoredPrint(
{
return String.Format("{0}:{1} {2}", color, msg, linkTxt);
}

/// <summary>
/// Item1 = Foreground, Item2 = Background.
/// </summary>
public static Tuple<UInt32, UInt32> LightThemeColor (Color color)
{
// https://coolors.co/palette/ffadad-ffd6a5-fdffb6-caffbf-9bf6ff-a0c4ff-bdb2ff-ffc6ff-fffffc
switch (color)
{
case Color.Blue:
return new Tuple<uint, uint>(0xFF000000, 0xFFA0C4FF);

case Color.Yellow:
return new Tuple<uint, uint>(0xFF000000, 0xFFFDFFB6);

case Color.Red:
return new Tuple<uint, uint>(0xFF000000, 0xFFFFADAD);

case Color.Black:
default:
return new Tuple<uint, uint>(0xFF000000, 0xFFFFFFFF);
}
}
}

public class StoredPrintsMinimalStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<None Remove="Resources\logo-mqtt.png" />
</ItemGroup>
<ItemGroup>
<None Update="AasxPluginMtpViewer.options.json">
<None Update="AasxPluginAssetInterfaceDesc.options.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="AasxPluginMtpViewer.plugin">
<None Update="AasxPluginAssetInterfaceDesc.plugin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand All @@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentModbus" Version="5.0.3" />
<PackageReference Include="MQTTnet" Version="4.3.3.952" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
74 changes: 74 additions & 0 deletions src/AasxPluginAssetInterfaceDesc/AidInterfaceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright (c) 2018-2023 Festo SE & Co. KG <https://www.festo.com/net/de_de/Forms/web/contact_international>
Author: Michael Hoffmeister
This source code is licensed under the Apache License 2.0 (see LICENSE.txt).
This source code may use other Open Source software components (see LICENSE.txt).
*/

using AasxIntegrationBase;
using AasxIntegrationBaseGdi;
using AdminShellNS;
using AnyUi;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;

namespace AasxPluginAssetInterfaceDescription
{
/// <summary>
/// This is thought as ONE service per ONE instance of AASX PE / BlazorExplorer
/// to care for all (continous) interfacing.
/// </summary>
public class AidInterfaceService
{
//
// Start of service
//

private LogInstance _log = new LogInstance();

private const int _timerTickMs = 200;
private System.Timers.Timer _dispatcherTimer = null;

private AidAllInterfaceStatus _allInterfaceStatus = null;

public void StartOperation(LogInstance log, AidAllInterfaceStatus allInterfaceStatus)
{
_log = log;
_allInterfaceStatus = allInterfaceStatus;

_dispatcherTimer = new System.Timers.Timer(_timerTickMs);
_dispatcherTimer.Elapsed += DispatcherTimer_Tick;
_dispatcherTimer.Enabled = true;
_dispatcherTimer.Start();
}

//
// Service
//

private bool _inDispatcherTimer = false;

private void DispatcherTimer_Tick(object sender, EventArgs e)
{
// access
if (_allInterfaceStatus == null || _inDispatcherTimer)
return;

// block
_inDispatcherTimer = true;

// ..

// release mutex
_inDispatcherTimer = false;

}
}
}
100 changes: 88 additions & 12 deletions src/AasxPluginAssetInterfaceDesc/AidInterfaceStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ public class AidInterfaceStatus
/// </summary>
public string EndpointBase = "";

/// <summary>
/// Actual summary of the status of the interface.
/// </summary>
public string LogLine = "";

/// <summary>
/// Black = idle, Blue = active, Red = error.
/// </summary>
public StoredPrint.Color LogColor = StoredPrint.Color.Black;

/// <summary>
/// Link to entity (interface).
/// </summary>
Expand Down Expand Up @@ -127,6 +137,11 @@ virtual public void Close()
virtual public void UpdateItemValue(AidIfxItemStatus item)
{
}

virtual public void PrepareContinousRun(IEnumerable<AidIfxItemStatus> items)
{

}
}

public class AidGenericConnections<T> : Dictionary<Uri, T> where T : AidBaseConnection, new()
Expand All @@ -151,7 +166,13 @@ public T GetOrCreate(string target)
/// </summary>
public class AidAllInterfaceStatus
{
public bool[] UseTech = { true, false, false };
public bool[] UseTech = { false, false, true };

/// <summary>
/// Will hold connections steady and continously update values, either by
/// timer pased polling or by subscriptions.
/// </summary>
public bool ContinousRun = false;

public List<AidInterfaceStatus> InterfaceStatus = new List<AidInterfaceStatus>();

Expand All @@ -161,11 +182,40 @@ public class AidAllInterfaceStatus
public AidGenericConnections<AidModbusConnection> ModbusConnections =
new AidGenericConnections<AidModbusConnection>();

public AidGenericConnections<AidMqttConnection> MqttConnections =
new AidGenericConnections<AidMqttConnection>();

protected AidBaseConnection GetOrCreate(AidInterfaceTechnology tech, string endpointBase)
{
// find connection by factory
AidBaseConnection conn = null;
switch (tech)
{
case AidInterfaceTechnology.HTTP:
conn = HttpConnections.GetOrCreate(endpointBase);
break;

case AidInterfaceTechnology.Modbus:
conn = ModbusConnections.GetOrCreate(endpointBase);
break;

case AidInterfaceTechnology.MQTT:
conn = MqttConnections.GetOrCreate(endpointBase);
break;
}
return conn;
}

/// <summary>
/// Will connect to each target once, get values and will disconnect again.
/// </summary>
public void UpdateValuesSingleShot()
{
// access allowed
if (ContinousRun)
return;

// for all
foreach (var tech in AdminShellUtil.GetEnumValues<AidInterfaceTechnology>())
{
// use?
Expand All @@ -180,17 +230,7 @@ public void UpdateValuesSingleShot()
continue;

// find connection by factory
AidBaseConnection conn = null;
switch (tech)
{
case AidInterfaceTechnology.HTTP:
conn = HttpConnections.GetOrCreate(ifc.EndpointBase);
break;

case AidInterfaceTechnology.Modbus:
conn = ModbusConnections.GetOrCreate(ifc.EndpointBase);
break;
}
AidBaseConnection conn = GetOrCreate(tech, ifc.EndpointBase);
if (conn == null)
continue;

Expand All @@ -212,6 +252,42 @@ public void UpdateValuesSingleShot()
ifc.Connection.Close();
}
}

/// <summary>
/// Will connect to each target, leave the connection open, will enable
/// cyclic updates.
/// </summary>
public void StartContinousRun()
{
// for all
foreach (var tech in AdminShellUtil.GetEnumValues<AidInterfaceTechnology>())
{
// use?
if (!UseTech[(int)tech])
continue;

// find all interfaces with that technology
foreach (var ifc in InterfaceStatus.Where((i) => i.Technology == tech))
{
// get a connection
if (ifc.EndpointBase?.HasContent() != true)
continue;

// find connection by factory
AidBaseConnection conn = GetOrCreate(tech, ifc.EndpointBase);
if (conn == null)
continue;

// open it
if (!conn.Open())
continue;
ifc.Connection = conn;

// start subscriptions ..
conn.PrepareContinousRun(ifc.Items);
}
}
}
}

}
Loading

0 comments on commit 8d97e2f

Please sign in to comment.