From a81220f2f0fdde486fc09162e84ecf2e814b30da Mon Sep 17 00:00:00 2001 From: Sina Blattmann Date: Fri, 30 Jun 2023 09:02:55 +0200 Subject: [PATCH 01/10] fix interpolate bug, fix graph bugs, remove modebar buttons --- typescript/Frontend/package-lock.json | 24 +++- typescript/Frontend/package.json | 3 +- .../Installations/Log/ScalarGraph.tsx | 16 ++- .../Installations/Log/TopologyBox.tsx | 135 +++++++++--------- .../Installations/Log/TopologyFlow.tsx | 4 +- .../Frontend/src/dataCache/dataCache.ts | 26 ++-- typescript/Frontend/src/util/graph.util.tsx | 56 ++++++-- 7 files changed, 163 insertions(+), 101 deletions(-) diff --git a/typescript/Frontend/package-lock.json b/typescript/Frontend/package-lock.json index d36bf3040..5b160b6da 100644 --- a/typescript/Frontend/package-lock.json +++ b/typescript/Frontend/package-lock.json @@ -57,7 +57,8 @@ "@formatjs/cli": "^6.0.3", "@types/react-plotly.js": "^2.6.0", "@types/react-window": "^1.8.5", - "eslint-plugin-formatjs": "^4.10.1" + "eslint-plugin-formatjs": "^4.10.1", + "prettier": "^2.8.8" } }, "node_modules/@adobe/css-tools": { @@ -19743,6 +19744,21 @@ "node": ">=0.10.0" } }, + "node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", @@ -39706,6 +39722,12 @@ "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz", "integrity": "sha512-PhmXi5XmoyKw1Un4E+opM2KcsJInDvKyuOumcjjw3waw86ZNjHwVUOOWLc4bCzLdcKNaWBH9e99sbWzDQsVaYg==" }, + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true + }, "pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/typescript/Frontend/package.json b/typescript/Frontend/package.json index 900de2c7a..e9719afc3 100644 --- a/typescript/Frontend/package.json +++ b/typescript/Frontend/package.json @@ -85,6 +85,7 @@ "@formatjs/cli": "^6.0.3", "@types/react-plotly.js": "^2.6.0", "@types/react-window": "^1.8.5", - "eslint-plugin-formatjs": "^4.10.1" + "eslint-plugin-formatjs": "^4.10.1", + "prettier": "^2.8.8" } } diff --git a/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx b/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx index 334688921..89a559628 100644 --- a/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx +++ b/typescript/Frontend/src/components/Installations/Log/ScalarGraph.tsx @@ -16,7 +16,7 @@ import { S3Access } from "../../../dataCache/S3/S3Access"; import DataCache, { FetchResult } from "../../../dataCache/dataCache"; import { LogContext } from "../../Context/LogContextProvider"; import { isDefined } from "../../../dataCache/utils/maybe"; -import { Data, Layout, PlotRelayoutEvent } from "plotly.js"; +import { Data, Icons, Layout, PlotRelayoutEvent, relayout } from "plotly.js"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import { FormattedMessage } from "react-intl"; import DateRangePicker from "./DateRangePicker"; @@ -45,6 +45,7 @@ export const fetchData = ( return Promise.resolve(FetchResult.notAvailable); } else if (r.status === 200) { const text = await r.text(); + console.log("parsecsv", text, parseCsv(text)); return parseCsv(text); } else { console.error("unexpected status code"); @@ -153,6 +154,7 @@ const ScalarGraph = () => { const handleRelayout = useCallback( (params: PlotRelayoutEvent) => { + console.log("relayout"); const xaxisRange0 = params["xaxis.range[0]"]; const xaxisRange1 = params["xaxis.range[1]"]; if (xaxisRange0 && xaxisRange1) { @@ -169,11 +171,8 @@ const ScalarGraph = () => { if (checkedToggles.length > 0) { const coordinateTimeSeries = transformToGraphData(timeSeries); const visibleGraphs = Object.keys(coordinateTimeSeries).filter((path) => { - console.log('checkedToggles',coordinateTimeSeries, checkedToggles) - return checkedToggles.find((toggle) => toggle === path) - } - ); - console.log('visibleGraphs', visibleGraphs) + return checkedToggles.find((toggle) => toggle === path); + }); if (visibleGraphs.length > 0) { return (
@@ -186,6 +185,8 @@ const ScalarGraph = () => { {visibleGraphs.map((path) => { const isScalar = isNumeric(coordinateTimeSeries[path].y[0]); + console.log("graphdata", timeSeries, coordinateTimeSeries); + const data = isScalar ? [ { @@ -203,7 +204,6 @@ const ScalarGraph = () => { barnorm: "percent", } : {}; - console.log("graphdata", coordinateTimeSeries); return ( { "select2d", "pan2d", "autoScale2d", + "resetScale2d", + "zoom2d", ], }} onRelayout={handleRelayout} diff --git a/typescript/Frontend/src/components/Installations/Log/TopologyBox.tsx b/typescript/Frontend/src/components/Installations/Log/TopologyBox.tsx index 3eb85a039..9f6a87ac2 100644 --- a/typescript/Frontend/src/components/Installations/Log/TopologyBox.tsx +++ b/typescript/Frontend/src/components/Installations/Log/TopologyBox.tsx @@ -1,79 +1,86 @@ -import {Box} from "@mui/material"; -import {getBoxColor} from "../../../util/graph.util"; +import { Box } from "@mui/material"; +import { getBoxColor } from "../../../util/graph.util"; + +export interface BoxDataValue { + unit: string; + value: string | number; +} export type BoxData = { - label: string; - values: (string | number)[]; - unit: string; + label: string; + values: BoxDataValue[]; }; export type TopologyBoxProps = { - title?: string; - data?: BoxData; + title?: string; + data?: BoxData; }; const isInt = (value: number) => { - return value % 1 === 0; + return value % 1 === 0; }; export const BOX_SIZE = 85; const TopologyBox = (props: TopologyBoxProps) => { - const {titleColor, boxColor} = getBoxColor(props.title); - return ( - -

- {props.title} -

-
- {props.data && ( - <> - {props.data.values.map((value, index) => { - return ( -

{`${ - props.data && props.data.values.length === 3 - ? "L" + (index + 1) + " " - : "" - }${ - !isInt(Number(value)) ? Number(value).toPrecision(4) : value - }${props.data?.unit}`}

- ); - })} - - )} -
-
- ); + const { titleColor, boxColor } = getBoxColor(props.title); + return ( + +

+ {props.title} +

+
+ {props.data && ( + <> + {props.data.values.map((boxData, index) => { + console.log("boxData", boxData); + return ( +

{`${ + props.data && props.data.values.length === 3 + ? "L" + (index + 1) + " " + : "" + }${ + !isInt(Number(boxData.value)) + ? Number(boxData.value).toPrecision(4) + : boxData.value + }${boxData.unit}`}

+ ); + })} + + )} +
+
+ ); }; export default TopologyBox; diff --git a/typescript/Frontend/src/components/Installations/Log/TopologyFlow.tsx b/typescript/Frontend/src/components/Installations/Log/TopologyFlow.tsx index 4f3912382..cc077eee4 100644 --- a/typescript/Frontend/src/components/Installations/Log/TopologyFlow.tsx +++ b/typescript/Frontend/src/components/Installations/Log/TopologyFlow.tsx @@ -43,9 +43,9 @@ const TopologyFlow = (props: TopologyFlowProps) => { }} > {values - ?.filter((value) => (value as number) !== 0) + ?.filter((boxData) => (boxData.value as number) !== 0) .map( - (value) => `${Math.round(value as number)} ${props.data?.unit}` + (boxData) => `${Math.round(boxData.value as number)} ${boxData.unit}` )}

> { const n = after.index - t; const pn = p + n; - let interpolated: Partial> = {}; + let interpolated: Record = {}; //What about string nodes? like Alarms for (const k of Object.keys(dataBefore)) { - const beforeData = dataBefore[k].value; - const afterData = Number(dataAfter[k].value); - let foo = interpolated[k]; - if (foo) { - foo.value = isNumber(beforeData) - ? (beforeData * n + afterData * p) / pn - : n < p - ? afterData - : beforeData; + const valueBefore = dataBefore[k].value; + const valueAfter = dataAfter[k]?.value as Maybe; + + let value: number | string; + + if (isUndefined(valueAfter)) { + value = valueBefore; + } else if (isNumber(valueBefore) && isNumber(valueAfter)) { + value = (valueBefore * n + valueAfter * p) / pn; + } else { + value = n < p ? valueAfter : valueBefore; } + + interpolated[k] = { value, unit: dataBefore[k].unit }; } return interpolated as T; diff --git a/typescript/Frontend/src/util/graph.util.tsx b/typescript/Frontend/src/util/graph.util.tsx index 9df5afb52..2c081982d 100644 --- a/typescript/Frontend/src/util/graph.util.tsx +++ b/typescript/Frontend/src/util/graph.util.tsx @@ -1,11 +1,12 @@ import { Datum, TypedArray } from "plotly.js"; -import { - TreeElement, -} from "../components/Installations/Log/CheckboxTree"; +import { TreeElement } from "../components/Installations/Log/CheckboxTree"; import { TimeRange, UnixTime } from "../dataCache/time"; import { DataPoint, DataRecord } from "../dataCache/data"; import { isDefined } from "../dataCache/utils/maybe"; -import { BoxData } from "../components/Installations/Log/TopologyBox"; +import { + BoxData, + BoxDataValue, +} from "../components/Installations/Log/TopologyBox"; export interface GraphCoordinates { x: Datum[] | Datum[][] | TypedArray; @@ -30,6 +31,7 @@ export const createTimes = ( ); return roundedRange.sample(oneSpan); }; + export interface GraphData { [path: string]: GraphCoordinates; } @@ -95,6 +97,7 @@ interface BoxColor { titleColor: string; boxColor: string; } + export const getBoxColor = (boxTitle?: string): BoxColor => { switch (boxTitle) { case "Grid": @@ -138,18 +141,33 @@ export const extractTopologyValues = ( const timeSeriesValue = timeSeriesData.value; if (isDefined(timeSeriesValue)) { return Object.keys(topologyPaths).reduce((acc, topologyKey) => { - let topologyValues: (string | number)[]; + let topologyValues: BoxDataValue[]; const values = topologyPaths[topologyKey as keyof TopologyValues].map( (topologyPath) => timeSeriesValue[topologyPath] ); switch (topologyKey as keyof TopologyValues) { case "gridToAcInConnection": topologyValues = [ - values.reduce((acc, curr) => Number(acc) + Number(curr.value), 0), + values.reduce( + (acc, curr) => { + return { + value: Number(acc.value) + Number(curr.value), + unit: acc.unit, + }; + }, + { value: 0, unit: values[0].unit } + ), ]; break; default: - topologyValues = values.map((element) => element.value); + topologyValues = values + .filter((element) => element) + .map((element) => { + if (element) { + return { value: element.value, unit: element.unit }; + } + return { value: 0, unit: "" }; + }); } return { ...acc, @@ -158,7 +176,6 @@ export const extractTopologyValues = ( label: topologyPaths[topologyKey as keyof TopologyValues][0] .split("/") .pop(), - unit: values[0].unit, } as BoxData, }; }, {} as TopologyValues); @@ -171,16 +188,22 @@ export const getHighestConnectionValue = (values: TopologyValues) => .filter((value) => value.includes("Connection")) .reduce((acc, curr) => { const value = Math.abs( - values[curr as keyof TopologyValues].values[0] as number + values[curr as keyof TopologyValues].values[0].value as number ); return value > acc ? value : acc; }, 0); export const getAmount = ( highestConnectionValue: number, - values: (string | number)[] + values: BoxDataValue[] ) => { - return Math.abs(values[0] as number) / highestConnectionValue; + console.log( + "getamount", + Math.abs(values[0].value as number) / highestConnectionValue, + Math.abs(values[0].value as number), + highestConnectionValue + ); + return Math.abs(values[0].value as number) / highestConnectionValue; }; export interface CsvEntry { @@ -189,23 +212,26 @@ export interface CsvEntry { } export const parseCsv = (text: string): DataRecord => { + console.log("parseText", text); const y = text .split(/\r?\n/) .filter((split) => split.length > 0) .map((l) => { return l.split(";"); }); - const x = y + return y .map((fields) => { - if (fields[0] === "/AcDc/Warnings") - console.log("warnings", fields[1], isNaN(+fields[1])); + if (fields[0].includes("LoadOnAcIsland")) { + console.log("fields", fields, { + [fields[0]]: { value: parseFloat(fields[1]), unit: fields[2] }, + }); + } if (isNaN(Number(fields[1])) || fields[1] === "") { return { [fields[0]]: { value: fields[1], unit: fields[2] } }; } return { [fields[0]]: { value: parseFloat(fields[1]), unit: fields[2] } }; }) .reduce((acc, current) => ({ ...acc, ...current }), {} as DataRecord); - return x; }; export const insertTreeElements = ( From 3fab366362041cc9a14ed1029df42e25388de685 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:23:37 +0200 Subject: [PATCH 02/10] Change the import as lib.props --- csharp/Lib/Devices/AMPT/Ampt.csproj | 4 +--- csharp/Lib/Devices/Adam6060/Adam6060.csproj | 5 +---- csharp/Lib/Devices/Adam6360D/Adam6360D.csproj | 4 +--- csharp/Lib/Devices/Battery48TL/Battery48TL.csproj | 4 ++-- csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs | 1 - csharp/Lib/Devices/EmuMeter/EmuMeter.csproj | 6 ++---- 6 files changed, 7 insertions(+), 17 deletions(-) diff --git a/csharp/Lib/Devices/AMPT/Ampt.csproj b/csharp/Lib/Devices/AMPT/Ampt.csproj index f2b0a1896..7fd4f243a 100644 --- a/csharp/Lib/Devices/AMPT/Ampt.csproj +++ b/csharp/Lib/Devices/AMPT/Ampt.csproj @@ -1,8 +1,6 @@ - + - - diff --git a/csharp/Lib/Devices/Adam6060/Adam6060.csproj b/csharp/Lib/Devices/Adam6060/Adam6060.csproj index 9c65e0cb7..beff437be 100644 --- a/csharp/Lib/Devices/Adam6060/Adam6060.csproj +++ b/csharp/Lib/Devices/Adam6060/Adam6060.csproj @@ -1,8 +1,5 @@ - - Debug;Release;Release-Server - AnyCPU;linux-arm - + diff --git a/csharp/Lib/Devices/Adam6360D/Adam6360D.csproj b/csharp/Lib/Devices/Adam6360D/Adam6360D.csproj index 0b06d7c44..85ed73706 100644 --- a/csharp/Lib/Devices/Adam6360D/Adam6360D.csproj +++ b/csharp/Lib/Devices/Adam6360D/Adam6360D.csproj @@ -1,8 +1,6 @@ - + - - diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TL.csproj b/csharp/Lib/Devices/Battery48TL/Battery48TL.csproj index 6df76f3b3..6fdebbf4f 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TL.csproj +++ b/csharp/Lib/Devices/Battery48TL/Battery48TL.csproj @@ -1,7 +1,7 @@ - - + + diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs index f595e95f8..45e41f8a5 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs @@ -1,7 +1,6 @@ using System.Diagnostics.CodeAnalysis; using InnovEnergy.Lib.Devices.Battery48TL.DataTypes; using InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes; -using InnovEnergy.Lib.SrcGen.Attributes; namespace InnovEnergy.Lib.Devices.Battery48TL; #pragma warning disable CS0169, CS0649 diff --git a/csharp/Lib/Devices/EmuMeter/EmuMeter.csproj b/csharp/Lib/Devices/EmuMeter/EmuMeter.csproj index 379b280a0..ee425fb8d 100644 --- a/csharp/Lib/Devices/EmuMeter/EmuMeter.csproj +++ b/csharp/Lib/Devices/EmuMeter/EmuMeter.csproj @@ -1,8 +1,6 @@ - - - - + + From 1d017ba6ba953c587852d430690903a15d98daf9 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:24:38 +0200 Subject: [PATCH 03/10] Add the hack to compile Net6 from Net7 --- csharp/Lib/Utils/HackToBuildNet6FromNet7.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 csharp/Lib/Utils/HackToBuildNet6FromNet7.cs diff --git a/csharp/Lib/Utils/HackToBuildNet6FromNet7.cs b/csharp/Lib/Utils/HackToBuildNet6FromNet7.cs new file mode 100644 index 000000000..9242d0f3c --- /dev/null +++ b/csharp/Lib/Utils/HackToBuildNet6FromNet7.cs @@ -0,0 +1,15 @@ +// TODO remove for .Net 7 +namespace System.Runtime.CompilerServices +{ + public class RequiredMemberAttribute : Attribute { } + public class CompilerFeatureRequiredAttribute : Attribute + { + public CompilerFeatureRequiredAttribute(string name) { } + } + +} + +namespace System.Diagnostics.CodeAnalysis +{ + public class SetsRequiredMembersAttribute : Attribute { } +} From 7d1544f34ae8e74075de32b76b710e9296217f88 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:25:14 +0200 Subject: [PATCH 04/10] change the target framework to net6.0 --- csharp/InnovEnergy.props | 2 +- csharp/global.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/csharp/InnovEnergy.props b/csharp/InnovEnergy.props index cc50081b0..b1a90c16d 100644 --- a/csharp/InnovEnergy.props +++ b/csharp/InnovEnergy.props @@ -6,7 +6,7 @@ preview true enable - net7.0 + net6.0 true false Please.reload.the.project.Rider.is.stupid diff --git a/csharp/global.json b/csharp/global.json index 9e5e1fd1d..7cd6a1f4f 100644 --- a/csharp/global.json +++ b/csharp/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.0", + "version": "7.0.0", "rollForward": "latestMajor", "allowPrerelease": true } From ca7d58ff0e616d9bb1ebb81a70fa783a8fe8f55a Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:26:04 +0200 Subject: [PATCH 05/10] Fix the run scripts --- csharp/App/SaliMax/run (Salimax 0001).sh | 4 +-- csharp/App/SaliMax/run (Salimax0003).sh | 34 +++++++++++++++++++ .../SaliMax/run (SalimnaxProto Meiringen).sh | 7 ++-- 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 csharp/App/SaliMax/run (Salimax0003).sh diff --git a/csharp/App/SaliMax/run (Salimax 0001).sh b/csharp/App/SaliMax/run (Salimax 0001).sh index a138c3067..2091f5208 100755 --- a/csharp/App/SaliMax/run (Salimax 0001).sh +++ b/csharp/App/SaliMax/run (Salimax 0001).sh @@ -2,7 +2,7 @@ dotnet_version='net6.0' salimax_ip= '10.2.3.104' -username='ie-entwicklung@' +username='ie-entwicklung' set -e @@ -11,7 +11,7 @@ echo -e "\n============================ Build ============================\n" dotnet publish \ ./SaliMax.csproj \ -c Release \ - -r linux-x64 + -r linux-x64 echo -e "\n============================ Deploy ============================\n" diff --git a/csharp/App/SaliMax/run (Salimax0003).sh b/csharp/App/SaliMax/run (Salimax0003).sh new file mode 100644 index 000000000..ba6f5b68c --- /dev/null +++ b/csharp/App/SaliMax/run (Salimax0003).sh @@ -0,0 +1,34 @@ +#!/bin/bash + +dotnet_version='net6.0' +salimax_ip='10.2.4.33' +username='ie-entwicklung' + +set -e + +echo -e "\n============================ Build ============================\n" + +dotnet publish \ + ./SaliMax.csproj \ + -p:PublishTrimmed=false \ + -c Release \ + -r linux-x64 + +echo -e "\n============================ Deploy ============================\n" + +rsync -v \ + ./bin/Release/$dotnet_version/linux-x64/publish/* \ + ie-entwicklung@10.2.4.33:~/salimax + +echo -e "\n============================ Restart Salimax sevice ============================\n" + +ssh -tt \ + ie-entwicklung@10.2.4.33 \ + sudo systemctl restart salimax.service + + +echo -e "\n============================ Print service output ============================\n" + +ssh -tt \ + ie-entwicklung@10.2.4.33 \ + journalctl -f -u salimax.service \ No newline at end of file diff --git a/csharp/App/SaliMax/run (SalimnaxProto Meiringen).sh b/csharp/App/SaliMax/run (SalimnaxProto Meiringen).sh index b9c4614cb..f41f8ee9b 100755 --- a/csharp/App/SaliMax/run (SalimnaxProto Meiringen).sh +++ b/csharp/App/SaliMax/run (SalimnaxProto Meiringen).sh @@ -1,9 +1,8 @@ #!/bin/bash - dotnet_version='net6.0' -salimax_ip= '10.2.3.115' -username='ie-entwicklung@' +salimax_ip='10.2.3.115' +username='ie-entwicklung' set -e @@ -13,7 +12,7 @@ dotnet publish \ ./SaliMax.csproj \ -p:PublishTrimmed=false \ -c Release \ - -r linux-x64 + -r linux-x64 echo -e "\n============================ Deploy ============================\n" From da38aa7b837902e6f64384ab9867cc43a40d978e Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:27:14 +0200 Subject: [PATCH 06/10] rename the log to loginfo and create log debug --- csharp/App/SaliMax/src/Ess/Controller.cs | 2 +- csharp/App/SaliMax/src/Logger.cs | 11 +++++++++-- csharp/App/SaliMax/src/SaliMaxRelays/RelaysDevice.cs | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/csharp/App/SaliMax/src/Ess/Controller.cs b/csharp/App/SaliMax/src/Ess/Controller.cs index 64fe03b05..7d6601450 100644 --- a/csharp/App/SaliMax/src/Ess/Controller.cs +++ b/csharp/App/SaliMax/src/Ess/Controller.cs @@ -187,7 +187,7 @@ public static class Controller if (statusRecord.Battery.Eoc) { - "Batteries have reached EOC".Log(); + "Batteries have reached EOC".LogInfo(); config.LastEoc = UnixTime.Now; return false; } diff --git a/csharp/App/SaliMax/src/Logger.cs b/csharp/App/SaliMax/src/Logger.cs index 56414bf66..f89ecb653 100644 --- a/csharp/App/SaliMax/src/Logger.cs +++ b/csharp/App/SaliMax/src/Logger.cs @@ -10,11 +10,18 @@ public static class Logger private const Int32 MaxLogFileCount = 1000; // TODO: move to settings private const String LogFilePath = "LogDirectory/log.txt"; // TODO: move to settings + // ReSharper disable once InconsistentNaming private static readonly ILogger _logger = new CustomLogger(LogFilePath, MaxFileSizeBytes, MaxLogFileCount); - public static T Log(this T t) where T : notnull + public static T LogInfo(this T t) where T : notnull { - // _logger.LogInformation(t.ToString()); // TODO: check warning + _logger.LogInformation(t.ToString()); // TODO: check warning + return t; + } + + public static T LogDebug(this T t) where T : notnull + { + _logger.LogDebug(t.ToString()); // TODO: check warning return t; } } \ No newline at end of file diff --git a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysDevice.cs b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysDevice.cs index e58e5ac26..31afb815c 100644 --- a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysDevice.cs +++ b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysDevice.cs @@ -18,7 +18,7 @@ public class RelaysDevice } catch (Exception e) { - $"Failed to read from {nameof(RelaysDevice)}\n{e}".Log(); + $"Failed to read from {nameof(RelaysDevice)}\n{e}".LogInfo(); // TODO: log return null; @@ -33,7 +33,7 @@ public class RelaysDevice } catch (Exception e) { - $"Failed to write to {nameof(RelaysDevice)}\n{e}".Log(); + $"Failed to write to {nameof(RelaysDevice)}\n{e}".LogInfo(); } } } From 5dfd8e69b4986494fb0938c2f0d8ec1a183dfc66 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:29:50 +0200 Subject: [PATCH 07/10] Change Dc link Window Voltage --- csharp/App/SaliMax/src/SystemConfig/Config.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/csharp/App/SaliMax/src/SystemConfig/Config.cs b/csharp/App/SaliMax/src/SystemConfig/Config.cs index 87febfdbd..ea5a82229 100644 --- a/csharp/App/SaliMax/src/SystemConfig/Config.cs +++ b/csharp/App/SaliMax/src/SystemConfig/Config.cs @@ -31,11 +31,11 @@ public class Config //TODO: let IE choose from config files (Json) and connect t LastEoc = UnixTime.Epoch, PConstant = .5, GridSetPoint = 0, - BatterySelfDischargePower = 200, // TODO: multiple batteries + BatterySelfDischargePower = 200, // TODO: multiple batteries // no need as we multiplied by the number of the batteries HoldSocZone = 1, // TODO: find better name, - MinDcBusVoltage = 730, + MinDcBusVoltage = 690, ReferenceDcBusVoltage = 750, - MaxDcBusVoltage = 770, + MaxDcBusVoltage = 810, }; @@ -50,7 +50,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t } catch (Exception e) { - $"Failed to write config file {configFilePath}\n{e}".Log(); + $"Failed to write config file {configFilePath}\n{e}".LogInfo(); throw; } } @@ -66,7 +66,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t } catch (Exception e) { - $"Failed to read config file {configFilePath}, using default config\n{e}".Log(); + $"Failed to read config file {configFilePath}, using default config\n{e}".LogInfo(); return Default; } } From 8fc2b8fe9d700911a36902670701a1bc486e8c2b Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:30:18 +0200 Subject: [PATCH 08/10] Create Individual Battery --- csharp/App/SaliMax/src/Program.cs | 70 ++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 0f35bac07..010d2a447 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -36,20 +36,23 @@ internal static class Program private static readonly Byte[] BatteryNodes = { 2, 3, 4, 5, 6 }; private const String BatteryTty = "/dev/ttyUSB0"; +#if DEBUG + private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001); + private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002); + private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003); + private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004); + private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005); + private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006); + private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007); +#else private static readonly TcpChannel RelaysChannel = new TcpChannel("10.0.1.1", 502); // "192.168.1.242"; private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("10.0.2.1", 502); // "192.168.1.2"; private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("10.0.3.1", 502); // "192.168.1.3"; private static readonly TcpChannel GridMeterChannel = new TcpChannel("10.0.4.1", 502); // "192.168.1.241"; private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("10.0.4.2", 502); // "192.168.1.241"; private static readonly TcpChannel AmptChannel = new TcpChannel("10.0.5.1", 502); // "192.168.1.249"; - - //private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001); - //private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002); - //private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003); - //private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004); - //private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005); - //private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006); - //private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007); + private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007); +#endif private static readonly S3Config S3Config = new S3Config @@ -165,7 +168,6 @@ internal static class Program Console.WriteLine("press ctrl-C to stop"); - while (true) { sd_notify(0, "WATCHDOG=1"); @@ -180,16 +182,7 @@ internal static class Program if (record.Relays is not null) record.Relays.ToCsv().WriteLine(); - - - var emuMeterRegisters = record.GridMeter; - if (emuMeterRegisters is not null) - { - emuMeterRegisters.Ac.Power.Active.WriteLine("Grid Active"); - //emuMeterRegisters.Ac.Power.Reactive.WriteLine("Grid Reactive"); - } - - + record.ControlConstants(); record.ControlSystemState(); @@ -272,12 +265,25 @@ internal static class Program var flowDcBusToDcDc = Flow.Horizontal(dcdcPower); var flowDcDcToBattery = Flow.Horizontal(dcBatteryPower); - var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid"); - var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter"); - var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC"); - var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), batterySoc.ToDisplayString(), batteryCurrent.ToDisplayString(), batteryTemp.ToDisplayString()).TitleBox("Battery"); + var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid"); + var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter"); + var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC"); + var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), + batterySoc.ToDisplayString(), + batteryCurrent.ToDisplayString(), + batteryTemp.ToDisplayString()) + .TitleBox("Battery"); + + //////////////////// Batteries ///////////////////////// + IReadOnlyList batteryBoxes = s.Battery + .Devices + .Select(CreateIndividualBattery) + .ToArray(s.Battery.Devices.Count); + + var individualBatteries = TextBlock.AlignLeft(batteryBoxes); + var totalBoxes = TextBlock.CenterVertical(gridBox, gridBusFlow, @@ -291,11 +297,25 @@ internal static class Program flowDcBusToDcDc, dcDcBox, flowDcDcToBattery, - batteryBox); - + batteryAvgBox, + individualBatteries); totalBoxes.WriteLine(); } + private static TextBlock CreateIndividualBattery(Battery48TlRecord battery, Int32 i) + { + var content = TextBlock.AlignLeft(battery.Dc.Voltage.ToDisplayString(), + battery.Soc.ToDisplayString(), + battery.Dc.Current.ToDisplayString(), + battery.Temperatures.Heating); + + var box = content.TitleBox($"Battery {i + 1}"); + + var flow = Flow.Horizontal(battery.Dc.Power); + + return TextBlock.CenterVertical(flow, box); + } + private static TextBlock ColumnBox(String pvTitle, String busTitle, String loadTitle, TextBlock dataBox) { return ColumnBox(pvTitle, busTitle, loadTitle, dataBox, 0); From c087af96c05ca43bc393036dcf3ffa5bebd9b694 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:30:50 +0200 Subject: [PATCH 09/10] Create an overload of CenterHorizantal --- csharp/Lib/Utils/TextBlock.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/csharp/Lib/Utils/TextBlock.cs b/csharp/Lib/Utils/TextBlock.cs index dc7fcb924..f7720d224 100644 --- a/csharp/Lib/Utils/TextBlock.cs +++ b/csharp/Lib/Utils/TextBlock.cs @@ -112,7 +112,7 @@ public class TextBlock return new TextBlock(alignedLines); } - public static TextBlock CenterHorizontal(params Object[] things) + public static TextBlock CenterHorizontal(IReadOnlyList things) { var lines = things .SelectMany(GetLines) @@ -127,6 +127,10 @@ public class TextBlock return new TextBlock(alignedLines); } + public static TextBlock CenterHorizontal(params Object[] things) + { + return CenterHorizontal((IReadOnlyList)things); + } public static TextBlock AlignTop(params Object[] things) { From 7a77982bd2b9be41a1e377e57c1ccab4a9cd0393 Mon Sep 17 00:00:00 2001 From: atef Date: Fri, 30 Jun 2023 10:31:13 +0200 Subject: [PATCH 10/10] Delete project refrence SrcGen --- csharp/Lib/Units/Units.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/csharp/Lib/Units/Units.csproj b/csharp/Lib/Units/Units.csproj index 13a09114c..f46fa951b 100644 --- a/csharp/Lib/Units/Units.csproj +++ b/csharp/Lib/Units/Units.csproj @@ -1,14 +1,10 @@ - - Debug;Release;Release-Server - AnyCPU;linux-arm - + -