Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Cbries/upgrade (#117)
Browse files Browse the repository at this point in the history
* fix useGroup exception

* plan update

* Change powerSwitch and Light control to mqtt

* fix tests

* fix build

* disable TrackPlanerTest tests

* update all package references

* improve path handling, update workspace

---------

Co-authored-by: Christian Benjamin Ries <c.ries@beckhoff.com>
  • Loading branch information
cbries and Christian Benjamin Ries committed Jun 22, 2023
1 parent 591cdb5 commit 6ae221d
Show file tree
Hide file tree
Showing 30 changed files with 37,264 additions and 22,192 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

- run: '& "$(vswhere -property installationPath)\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" Testing\ecoslibServerNetTest\bin\Release\ecoslibServerNetTest.dll'
- run: '& "$(vswhere -property installationPath)\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" Testing\TrackPlanerTest\bin\Release\net5.0\TrackPlanerTest.dll'
#- run: '& "$(vswhere -property installationPath)\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" Testing\TrackPlanerTest\bin\Release\net7.0\TrackPlanerTest.dll'
- run: '& "$(vswhere -property installationPath)\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" Testing\UtilitiesTest\bin\Release\UtilitiesTest.dll'


Expand Down
40 changes: 29 additions & 11 deletions EcosApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,21 @@ function relayWebsocketCommand(data) {
});
}

function triggerMqttMessage(data) {
var srv = window.serverHandling;
if (typeof srv === "undefined" || srv == null)
return; // TODO show error

// data.mode := string ['mqtt', ...]
// data.data := object, binary, etc.

srv.sendCommand({
"command": "mqtt",
"timestamp": Date.now(),
"cmddata": data
});
}

function removeTextfieldFromGlobalList(uniqueId) {
if (uniqueId == null)
return;
Expand Down Expand Up @@ -461,13 +476,17 @@ $(document).ready(function () {

window.dialogLightAndPower = new LightAndPower();
window.dialogLightAndPower.install();
window.dialogLightAndPower.on('relayCommand', function (ev) {
let fncPowerLightChanged = function (ev) {
const data = ev.data;
if (data.mode === "websocket")
relayWebsocketCommand(data);
else
console.log("TODO unknown relay mode: " + data.mode);
});
if (data.mode === "mqtt") {
triggerMqttMessage(data);
}
else {
console.log("TODO unknown data mode: " + data.mode);
}
};
window.dialogLightAndPower.on('powerSwitchesChanged', fncPowerLightChanged);
window.dialogLightAndPower.on('lightChanged', fncPowerLightChanged);

window.dialogS88 = new FeedbackVisualization();
window.dialogS88.install();
Expand Down Expand Up @@ -732,29 +751,28 @@ $(document).ready(function () {
const state = jsonCommand.data.state;
if (typeof state === "undefined" || state == null) break;

const fncClearGhost = function() {
const fncClearGhost = function () {
const allFbItems = $('div.ctrlItemFeedback[id]');
const iMax = allFbItems.length;
for (let i = 0; i < iMax; ++i) {
$(allFbItems[i]).removeClass("ghost");
}
}

const fncHideGhostOverlay = function() {
const fncHideGhostOverlay = function () {
$('.overlayGhost').hide();
$('.overlayGhostText').hide();
}

const fncShowGhostOverlay = function(message) {
const fncShowGhostOverlay = function (message) {
$('.overlayGhost').show();
$('.overlayGhostText').html(message);
$('.overlayGhostText').show();
}

if (typeof state.found === "undefined"
|| state.found == null
|| state.found === false)
{
|| state.found === false) {
fncClearGhost();
fncHideGhostOverlay();
} else {
Expand Down
5 changes: 2 additions & 3 deletions EcosApp/libs/w2ui-1.5.rc1/w2ui-1.5.rc1.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,11 @@ var w2utils = (function ($) {
return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i === 0 ? 0 : 1) + ' ' + (sizes[i] || '??');
}

function formatNumber (val, fraction, useGrouping) {
function formatNumber (val, fraction) {
if (val == null || val === '' || typeof val == 'object') return '';
var options = {
minimumFractionDigits : fraction,
maximumFractionDigits : fraction,
useGrouping : useGrouping
maximumFractionDigits : fraction
};
if (fraction == null || fraction < 0) {
options.minimumFractionDigits = 0;
Expand Down
4 changes: 2 additions & 2 deletions EcosApp/railessentials.min.js

Large diffs are not rendered by default.

57 changes: 31 additions & 26 deletions EcosApp/src/lightAndPower.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class LightAndPower {
}
catch (e) { }
});

$('#powerChkIn1DelaySecs').w2field('int', {
autoFormat: true, min: 0, max: 30, silent: false
});
Expand Down Expand Up @@ -351,29 +352,32 @@ class LightAndPower {
const self = this;
const dataToSend = self.__getRgbStripesObject();

self.__trigger('relayCommand',
self.__trigger('lightChanged',
{
'mode': 'websocket',
'target': this.__rgbStripesIpAddr,
'contentType': 'application/json',
'mode': 'mqtt',
'data': dataToSend
});
}

__getRgbStripesObject() {
let rgbW = { r: 255, g: 255, b: 255, w: 1023 };
let rgbW = {
"Haus/Railway/Sky/R": 255,
"Haus/Railway/Sky/G": 255,
"Haus/Railway/Sky/B": 255,
"Haus/Railway/Sky/W": 1023
};
if ($('#rgbColorMorningRadio').is(":checked") === true) {
rgbW = hexToRgbA($('#rgbColorMorning').val());
rgbW.w = 200;
rgbW = hexToRgbA('Haus/Railway/Sky/', $('#rgbColorMorning').val());
rgbW['Haus/Railway/Sky/W'] = 200;
} else if ($('#rgbColorNoonRadio').is(":checked") === true) {
rgbW = hexToRgbA($('#rgbColorNoon').val());
rgbW.w = 1023;
rgbW = hexToRgbA('Haus/Railway/Sky/', $('#rgbColorNoon').val());
rgbW['Haus/Railway/Sky/W'] = 1023;
} else if ($('#rgbColorAfternoonRadio').is(":checked") === true) {
rgbW = hexToRgbA($('#rgbColorAfternoon').val());
rgbW.w = 500;
rgbW = hexToRgbA('Haus/Railway/Sky/', $('#rgbColorAfternoon').val());
rgbW['Haus/Railway/Sky/W'] = 500;
} else if ($('#rgbColorNightRadio').is(":checked") === true) {
rgbW = hexToRgbA($('#rgbColorNight').val());
rgbW.w = 100;
rgbW = hexToRgbA('Haus/Railway/Sky/', $('#rgbColorNight').val());
rgbW['Haus/Railway/Sky/W'] = 100;
}

return rgbW;
Expand All @@ -382,22 +386,23 @@ class LightAndPower {
__sendPowerSwitch() {
const self = this;
const dataToSend = {
"in1": $('#powerChkIn1').is(":checked"),
"in2": $('#powerChkIn2').is(":checked"),
"in3": $('#powerChkIn3').is(":checked"),
"in4": $('#powerChkIn4').is(":checked"),

//"in1delay": parseInt($('#powerChkIn1DelaySecs').val()),
//"in2delay": parseInt($('#powerChkIn2DelaySecs').val()),
//"in3delay": parseInt($('#powerChkIn3DelaySecs').val()),
//"in4delay": parseInt($('#powerChkIn4DelaySecs').val())
"Haus/Switches/Railway01": $('#powerChkIn1').is(":checked"),
"Haus/Switches/Railway02": $('#powerChkIn2').is(":checked"),
"Haus/Switches/Railway03": $('#powerChkIn3').is(":checked"),
"Haus/Switches/Railway04": $('#powerChkIn4').is(":checked"),
};

self.__trigger('relayCommand',
// MQTT
// Haus/Switches/Railway01 True|False
// Haus/Switches/Railway02 True|False
// Haus/Switches/Railway03 True|False
// Haus/Switches/Railway04 True|False
// Haus/Switches/Off
// Haus/Switches/On

self.__trigger('powerSwitchesChanged',
{
'mode': 'websocket',
'target': this.__powerPlugIpAddr,
'contentType': 'application/json',
'mode': 'mqtt',
'data': dataToSend
});
}
Expand Down
22 changes: 14 additions & 8 deletions EcosApp/src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ returned value: (String)
rgba(251,175,255,1)
hexToRgbA('#fbafff')
*/
function hexToRgbA(hex) {
function hexToRgbA(topic, hex) {
if (hex.charAt(0) !== '#')
hex = '#' + hex;
var c;
Expand All @@ -72,13 +72,19 @@ function hexToRgbA(hex) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c = '0x' + c.join('');
//return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',1)';
return {
r: (c >> 16) & 255,
g: (c >> 8) & 255,
b: c & 255,
w: 1023
};

var r = topic + 'R';
var g = topic + 'G';
var b = topic + 'B';
var w = topic + 'W';

var o = {};
o[r] = (c >> 16) & 255;
o[g] = (c >> 8) & 255;
o[b] = c & 255;
o[w] = 1023;

return o;
}
throw new Error('Bad Hex');
}
Expand Down
6 changes: 3 additions & 3 deletions Testing/TrackPlanerTest/TestMetamodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,10 @@ public void TestRoutingConnectorDemo()
[TestMethod]
public void TestRoutingBasementDemo()
{
var path = WorkspaceRoot + @"Basement\metamodel.json";
var path = WorkspaceRoot + @"BasementTest\metamodel.json";
var field = LoadPlanFieldFile(path);

var startBlock = field["8x9"];
var startBlock = field["7x8"];
var r8_9 = field.GetRoutes(startBlock);
var targetBlock = field["21x18"];
foreach (var itR in r8_9)
Expand Down Expand Up @@ -688,7 +688,7 @@ public void TestCrossingSwitchDirections2()
[TestMethod]
public void TestAnalyzer()
{
var path = WorkspaceRoot + @"Basement\metamodel.json";
var path = WorkspaceRoot + @"BasementTest\metamodel.json";
var field = LoadPlanFieldFile(path);

var analyzer = new Analyze(field);
Expand Down
14 changes: 7 additions & 7 deletions Testing/TrackPlanerTest/TrackPlanerTest.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="HtmlTags" Version="8.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions Testing/UtilitiesTest/UtilitiesTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions">
<Version>5.10.3</Version>
<Version>6.11.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.2.3</Version>
<Version>3.0.4</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.2.3</Version>
<Version>3.0.4</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Testing/ecoslibServerNetTest/ecoslibServerNetTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions">
<Version>5.10.3</Version>
<Version>6.11.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.2.3</Version>
<Version>3.0.4</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.2.3</Version>
<Version>3.0.4</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions Utilities/StringUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// File: StringUtilities.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Utilities
Expand Down Expand Up @@ -40,5 +42,43 @@ public static bool WriteAllTextNoBom(string path, string content, out string err
return false;
}
}

public static string RemoveInvalidFileNameChars(this string filename)
{
if (string.IsNullOrEmpty(filename)) return filename;
var parts = filename.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 0) return filename;

var fname = parts.Last();
var p = filename;
p = p.Replace(fname, string.Empty);
p = p.TrimEnd(new[] {'/'});

fname = string.Join("_", fname.Split(Path.GetInvalidFileNameChars()));
return Path.Combine(p, fname);
}

private static readonly List<string> ImageExtensions = new()
{
".jpg",
".jpeg",
".png",
".gif",
".bmp",
".tif",
".tiff",
".ico",
".svg"
};

public static bool IsImageFileExtension(this string filename)
{
if (string.IsNullOrEmpty(filename)) return false;
foreach(var it in ImageExtensions)
if (filename.EndsWith(it, StringComparison.OrdinalIgnoreCase))
return true;

return false;
}
}
}
2 changes: 1 addition & 1 deletion Utilities/Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 6ae221d

Please sign in to comment.