From 340990573f348e0a1aa293f0028321fa568c714a Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 9 Jul 2025 09:59:53 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20automatische=20Moduserkennung=20f=C3=BC?= =?UTF-8?q?r=20fetchAnalogInputsService.ts=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modus wird anhand von window.location.hostname bestimmt - Lokale Umgebung (localhost/127.0.0.1) nutzt Mock-API - Produktionsumgebung lädt analogInputs.json via CGI - Kein Bedarf mehr für manuelle .env-Konfiguration --- .env.development | 2 +- .env.production | 2 +- CHANGELOG.md | 10 +++ .../SERVICE/analogInputsMockData.json | 72 +++++++++++++++---- package-lock.json | 4 +- package.json | 2 +- services/fetchAnalogInputsService.ts | 44 ++++-------- 7 files changed, 85 insertions(+), 51 deletions(-) diff --git a/.env.development b/.env.development index ec40335..29559e7 100644 --- a/.env.development +++ b/.env.development @@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false NEXT_PUBLIC_EXPORT_STATIC=false NEXT_PUBLIC_USE_CGI=false # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.6.567 +NEXT_PUBLIC_APP_VERSION=1.6.568 NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter) diff --git a/.env.production b/.env.production index 7290d6c..981b970 100644 --- a/.env.production +++ b/.env.production @@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL NEXT_PUBLIC_EXPORT_STATIC=true NEXT_PUBLIC_USE_CGI=true # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.6.567 +NEXT_PUBLIC_APP_VERSION=1.6.568 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f8de843..4f95072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [1.6.568] – 2025-07-09 + +- feat: Modus-Erkennung über window.location.hostname implementiert + +- Automatische Umschaltung zwischen Entwicklungs- und Produktionsmodus +- Hostname-basierte Erkennung: localhost/127.0.0.1 → "dev", sonst → "production" +- fetchDigitalInputsService.ts entsprechend angepasst +- Erleichtert Entwicklung und reduziert manuelle .env-Konfiguration + +--- ## [1.6.567] – 2025-07-09 - feat: CGI-kompatiblen CSV-Parser für digitale Eingänge implementiert diff --git a/mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json b/mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json index df14d2e..778c203 100644 --- a/mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json +++ b/mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json @@ -1,21 +1,63 @@ { "win_analogInputsValues": [ - 4.771072, 5.665244, 0.005467, -0.007468, 0.000002, 0.000001, 0.000001, - 0.000007 + "126.630287", + "5.667177", + "-0.000531", + "0.012762", + "-0.000001", + "0.000009", + "-0.000002", + "-0.000012" ], "win_analogInputsLabels": [ - "AE 1", - "AE 2", - "AE 3", - "AE 4", - "AE 5", - "AE 6", - "AE 7", - "AE 8" + "'AE 1'", + "'Temperatur'", + "'AE 3'", + "'AE 4'", + "'AE 5'", + "'AE 6'", + "'AE 7'", + "'AE 8'" ], - "win_analogInputsOffset": [10.988, 0, 0, 0, 0, 0, 0, 0], - "win_analogInputsFactor": [11.988, 1, 1, 1, 1, 1, 1, 1], - "win_analogInputsUnits": ["V", "V", "V", "V", "mA", "mA", "mA", "mA"], - "win_analogInputsLoggerIntervall": [7, 10, 10, 10, 10, 10, 10, 10], - "win_analogInputsWeighting": [0, 0, 0, 0, 0, 0, 0, 0] + "win_analogInputsUnits": [ + "'V'", + "'V'", + "'V'", + "'V'", + "'mA'", + "'mA'", + "'mA'", + "'mA'" + ], + "win_analogInputsFactor": [ + "21.999", + "1.000", + "1.000", + "1.000", + "1.000", + "1.000", + "1.000", + "1.000" + ], + "win_analogInputsOffset": [ + "21.999", + "0.000", + "0.000", + "0.000", + "0.000", + "0.000", + "0.000", + "0.000" + ], + "win_analogInputsWeighting": ["0", "0", "0", "0", "0", "0", "0", "0"], + "win_analogInputsLoggerIntervall": [ + "21", + "10", + "10", + "10", + "10", + "10", + "10", + "10" + ] } diff --git a/package-lock.json b/package-lock.json index 3b90954..a941de4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cpl-v4", - "version": "1.6.567", + "version": "1.6.568", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cpl-v4", - "version": "1.6.567", + "version": "1.6.568", "dependencies": { "@fontsource/roboto": "^5.1.0", "@headlessui/react": "^2.2.4", diff --git a/package.json b/package.json index c2ece63..1672999 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cpl-v4", - "version": "1.6.567", + "version": "1.6.568", "private": true, "scripts": { "dev": "next dev", diff --git a/services/fetchAnalogInputsService.ts b/services/fetchAnalogInputsService.ts index e42e5cc..31afa0e 100644 --- a/services/fetchAnalogInputsService.ts +++ b/services/fetchAnalogInputsService.ts @@ -1,12 +1,14 @@ // services/fetchAnalogInputsService.ts export const fetchAnalogInputsService = async () => { - const mode = process.env.NEXT_PUBLIC_CPL_MODE; + // 🌐 Automatische Moduserkennung über Hostname + const hostname = window.location.hostname; + const mode = + hostname === "localhost" || hostname === "127.0.0.1" ? "dev" : "production"; + // ✅ PRODUKTIV: lädt JSON-Datei vom Gerät über CGI if (mode === "production") { - console.log( - "🔄 Lade analoge Eingänge im Produktionsmodus (JSON über CPL?)..." - ); + console.log("🔄 Lade analoge Eingänge im Produktionsmodus (JSON über CGI)"); const res = await fetch("/CPL?/CPL/SERVICE/analogInputs.json", { headers: { Accept: "application/json" }, @@ -30,13 +32,16 @@ export const fetchAnalogInputsService = async () => { })); } - // ✅ jsSimulatedProd-MODUS (Script einbinden und aus window lesen) - else if (mode === "jsSimulatedProd") { - console.log("🧪 Lade analoge Eingänge im Simulationsmodus (JSON)"); + // ✅ ENTWICKLUNG: Daten vom lokalen API-Mock + else { + console.log( + "🧪 Lade analoge Eingänge im Entwicklungsmodus (Mock über API)" + ); const res = await fetch("/api/cpl/getAnalogInputsHandler"); - if (!res.ok) + if (!res.ok) { throw new Error("❌ Fehler beim Laden der analogen Eingänge (Mock)"); + } const data = await res.json(); @@ -51,27 +56,4 @@ export const fetchAnalogInputsService = async () => { weighting: parseInt(data.win_analogInputsWeighting[i]), })); } - - // ✅ JSON-MODUS (API gibt JSON-Daten zurück) - else if (mode === "json") { - console.log("🔄 Lade analoge Eingänge im JSON-Modus..."); - const res = await fetch("/api/cpl/getAnalogInputsHandler"); - if (!res.ok) throw new Error("❌ Fehler beim Laden der analogen Eingänge"); - - const data = await res.json(); - console.log("📡 Analoge Eingänge geladen:", data); - - return data.win_analogInputsValues.map((value: number, i: number) => ({ - id: i + 1, - value, - label: data.win_analogInputsLabels[i], - unit: data.win_analogInputsUnits[i], - offset: parseFloat(data.win_analogInputsOffset[i]), - factor: parseFloat(data.win_analogInputsFactor[i]), - loggerInterval: parseInt(data.win_analogInputsLoggerIntervall[i]), - weighting: parseInt(data.win_analogInputsWeighting[i]), - })); - } else { - throw new Error(`Unbekannter Modus: ${mode}`); - } };