Kabelüberwachung liest aus Redux

This commit is contained in:
ISA
2024-11-05 08:25:18 +01:00
parent 228d8d7a1b
commit 1cdd77be09
8 changed files with 277 additions and 582 deletions

View File

@@ -2,6 +2,7 @@
import React, { useState, useEffect } from "react";
import ReactModal from "react-modal";
import Chart from "chart.js/auto";
import { useSelector } from "react-redux";
import KueModal from "../modales/KueModal";
import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons
@@ -35,107 +36,110 @@ function Kue705FO({
schleifenwiderstand || "0"
);
const [showModal, setShowModal] = useState(false);
const [showChartModal, setShowChartModal] = useState(false); // Modal für die Messkurve
const [chartData, setChartData] = useState(null); // State für die geladene Chart-Daten
const [showChartModal, setShowChartModal] = useState(false);
const [chartData, setChartData] = useState(null);
const handleOpenModal = () => {
setShowModal(true);
};
// Redux-Variablen abrufen
const {
kuePSTmMinus96V,
kueCableBreak,
kueGroundFault,
kueAlarm1,
kueAlarm2,
kueOverflow,
kueVersion: reduxKueVersion,
tdrActive,
} = useSelector((state) => state.variables);
const handleCloseModal = () => {
setShowModal(false);
};
const handleOpenModal = () => setShowModal(true);
const handleCloseModal = () => setShowModal(false);
// Funktion zum Anzeigen des Chart-Modals
const handleOpenChartModal = () => {
setShowChartModal(true);
if (activeButton === "TDR") {
loadTDRChartData(); // Lade TDR-Daten, wenn der TDR-Button aktiv ist
loadTDRChartData();
} else {
loadLoopChartData(); // Andernfalls lade die Schleifenmessdaten
loadLoopChartData();
}
};
const handleButtonClick = (button) => {
if (button === "Schleife") {
setActiveButton("Schleife");
setloopTitleText("Schleifenwiderstand [kOhm]");
setCurrentDisplayValue(schleifenwiderstand || "0");
} else if (button === "TDR") {
setActiveButton("TDR");
setloopTitleText("Entfernung [Km]");
setCurrentDisplayValue(tdrLocation || "0");
}
};
// Bestimme, welche Funktion ausgeführt wird, basierend auf dem aktiven Button
const handleRefreshClick = () => {
if (activeButton === "Schleife") {
goLoop(); // Wenn Schleife aktiv ist, starte goLoop
} else if (activeButton === "TDR") {
goTDR(); // Wenn TDR aktiv ist, starte goTDR
}
};
const handleCloseChartModal = () => {
setShowChartModal(false);
};
const environment = process.env.NODE_ENV || "production";
let fileData;
// Daten laden und den TDR-Chart erstellen
const handleCloseChartModal = () => setShowChartModal(false);
const loadTDRChartData = () => {
const slot = slotIndex;
//const fileData = `../cpl?lastTDR/slot${slot}.json`; // TDR-Daten je nach Slot laden
if (environment === "production") {
fileData = `/CPL?/CPL/lastTDR/slot${slot}.json`; // Produktions-Pfad
} else {
fileData = `/CPLmockData/lastTDR/slot${slot}.json`; // Mock-Daten-Pfad für Entwicklung
}
const environment = process.env.NODE_ENV || "production";
const fileData =
environment === "production"
? `/CPL?/CPL/lastTDR/slot${slot}.json`
: `/CPLmockData/lastTDR/slot${slot}.json`;
fetch(fileData)
.then((response) => response.json())
.then((data) => {
setChartData(data); // Daten setzen
createTDRChart(data); // Chart für TDR-Messung erstellen
setChartData(data);
createTDRChart(data);
})
.catch((error) => {
console.error("Fehler beim Laden der TDR-Messkurvendaten:", error);
});
.catch((error) =>
console.error("Fehler beim Laden der TDR-Messkurvendaten:", error)
);
};
// Daten laden und den Schleifenmessungs-Chart erstellen
const loadLoopChartData = () => {
const slot = slotIndex;
//const fileData = `../cpl?4000values/slot${slot}.json`; // Schleifenmessdaten je nach Slot laden
if (environment === "production") {
fileData = `/CPL?/CPL/4000values/slot${slot}.json`; // Produktions-Pfad
} else {
fileData = `/CPLmockData/4000values/slot${slot}.json`; // Mock-Daten-Pfad für Entwicklung
}
const environment = process.env.NODE_ENV || "production";
const fileData =
environment === "production"
? `/CPL?/CPL/4000values/slot${slot}.json`
: `/CPLmockData/4000values/slot${slot}.json`;
fetch(fileData)
.then((response) => response.json())
.then((data) => {
setChartData(data); // Daten setzen
createChart(data, "Schleifenmesskurve"); // Chart für Schleifenmessung erstellen
setChartData(data);
createChart(data, "Schleifenmesskurve");
})
.catch((error) => {
console.error("Fehler beim Laden der Schleifenmesskurvendaten:", error);
});
.catch((error) =>
console.error("Fehler beim Laden der Schleifenmesskurvendaten:", error)
);
};
// Funktion zum Erstellen des Charts
// Funktion zum Erstellen des Charts
const createChart = (data) => {
const ctx = document.getElementById("myChart").getContext("2d");
// Funktion zur Umwandlung des Datums in das deutsche Format
const formatToGermanDate = (timestamp) => {
const date = new Date(timestamp);
return new Intl.DateTimeFormat("de-DE", {
day: "2-digit",
month: "2-digit",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
}).format(date);
};
// Ausgabe der Chart-Daten in der Konsole mit Slot-Informationen
console.log(`Chart-Daten für Slot ${slotIndex + 1}:`, data);
new Chart(ctx, {
type: "line",
data: {
labels: data.map((row) => formatToGermanDate(row.t)).reverse(), // Zeitwerte ins deutsche Format umwandeln und umkehren
labels: data
.map((row) => new Date(row.t).toLocaleString("de-DE"))
.reverse(),
datasets: [
{
label: "Isolationswiderstand (MOhm)", // Einheit hinzugefügt
label: "Isolationswiderstand (MOhm)",
data: data.map((row) => row.m).reverse(),
borderColor: "#00AEEF",
fill: false,
yAxisID: "y",
},
{
label: "Schleifenwiderstand (kOhm)", // Einheit hinzugefügt
label: "Schleifenwiderstand (kOhm)",
data: data.map((row) => row.n).reverse(),
borderColor: "black",
fill: false,
@@ -148,272 +152,82 @@ function Kue705FO({
y: {
type: "linear",
position: "left",
title: {
display: true,
text: "MOhm", // Einheit für linke Achse hinzugefügt
},
title: { display: true, text: "MOhm" },
},
y1: {
type: "linear",
position: "right",
title: {
display: true,
text: "kOhm", // Einheit für rechte Achse hinzugefügt
},
},
},
},
});
};
// Funktion zum Erstellen des TDR-Charts
const createTDRChart = (dataTDR) => {
const ctx = document.getElementById("myChart").getContext("2d");
console.log(`TDR-Daten für Slot ${slotIndex + 1}:`, dataTDR);
new Chart(ctx, {
type: "line",
data: {
labels: dataTDR.map((row) => row.t), // Entfernung oder Zeit auf der x-Achse
datasets: [
{
label: "Pegel",
data: dataTDR.map((row) => row.m), // Nur Pegel auf der y-Achse
borderColor: "#00AEEF",
borderWidth: 1,
pointBorderWidth: 0,
pointStyle: false,
fill: false,
},
],
},
options: {
scales: {
y: {
type: "linear",
position: "left",
title: { display: true, text: "kOhm" },
},
},
},
});
};
// Funktion für die TDR-Messung
const goTDR = () => {
//-------------------------------------------------
/* const [isClient, setIsClient] = useState(false);
useEffect(() => {
// This will only run in the client/browser, not on the server
setIsClient(true);
}, []);
if (!isClient) {
return null; // or a loading spinner
} */
//-------------------------------------------------
let slot = slotIndex;
if (slot >= 32) {
return;
}
let slotFormat = slot < 10 ? `0${slot}` : `${slot}`;
setLoading(true);
alert(`TDR wird für Slot ${slot + 1} gestartet...`);
fetch(`/CPL?Service/KUEdetailTDR.ACP&KTT${slotFormat}=1&slot=${slot}`, {
method: "GET",
})
.then((response) => {
if (response.ok) {
alert(`TDR erfolgreich gestartet für Slot ${slot + 1}`);
console.log("TDR erfolgreich gestartet für Slot", slot + 1);
} else {
console.error("Fehler beim Senden der TDR-Anfrage");
}
})
.catch((error) => {
console.error("Fehler:", error);
})
.finally(() => setLoading(false));
};
// Funktion für die Schleifenmessung
const goLoop = () => {
let slot = slotIndex;
if (slot >= 32) {
return;
}
let slotFormat = slot < 10 ? `0${slot}` : `${slot}`;
setLoading(true); // Setze den Ladezustand auf true
alert(`Schleifenmessung wird für Slot ${slot} gestartet...`);
fetch(`/CPL?Service/KUEdetail.HTML&KS_${slotFormat}=1&slot=${slot}`, {
method: "GET",
})
.then((response) => {
if (response.ok) {
alert(`Schleifenmessung erfolgreich gestartet für Slot ${slot}`);
console.log("Schleifenmessung erfolgreich gestartet für Slot", slot);
} else {
alert("Fehler beim Starten der Schleifenmessung.");
console.error("Fehler beim Senden der Schleifen-Anfrage");
}
})
.catch((error) => {
alert("Ein Fehler ist aufgetreten.");
console.error("Fehler:", error);
})
.finally(() => setLoading(false)); // Ladezustand zurücksetzen
};
const handleModulNameChange = (newName) => {
setCurrentModulName(newName);
};
// Überprüfe, ob ein Modul im Slot vorhanden ist
const isModulPresent = kueOnline === 1; // Since you're passing the status directly now
const handleButtonClick = (button) => {
if (button === "Schleife") {
setActiveButton("Schleife");
setloopTitleText("Schleifenwiderstand [kOhm]");
setCurrentDisplayValue(schleifenwiderstand || "0");
} else if (button === "TDR") {
setActiveButton("TDR");
setloopTitleText("Entfernung [Km]");
setCurrentDisplayValue(tdrLocation || "0");
}
};
// Bestimme, welche Funktion ausgeführt wird, basierend auf dem aktiven Button
const handleRefreshClick = () => {
if (activeButton === "Schleife") {
goLoop(); // Wenn Schleife aktiv ist, starte goLoop
} else if (activeButton === "TDR") {
goTDR(); // Wenn TDR aktiv ist, starte goTDR
}
};
useEffect(() => {
setCurrentModulName(modulName);
}, [modulName]);
useEffect(() => {
setCurrentDisplayValue(schleifenwiderstand);
}, [schleifenwiderstand]);
useEffect(() => {
const updateAlarmStatus = () => {
const alarmStatus =
(window.kueAlarm1 && window.kueAlarm1[slotIndex]) ||
(window.kueAlarm2 && window.kueAlarm2[slotIndex]) ||
(window.kueCableBreak && window.kueCableBreak[slotIndex]) ||
(window.kueGroundFault && window.kueGroundFault[slotIndex]);
(kueAlarm1 && kueAlarm1[slotIndex]) ||
(kueAlarm2 && kueAlarm2[slotIndex]) ||
(kueCableBreak && kueCableBreak[slotIndex]) ||
(kueGroundFault && kueGroundFault[slotIndex]);
setCurrentAlarmStatus(alarmStatus); // Aktualisiere den Alarmstatus
setCurrentAlarmStatus(alarmStatus);
};
// Aktualisierung sofort und alle 5 Sekunden
updateAlarmStatus();
const interval = setInterval(updateAlarmStatus, 10000);
return () => clearInterval(interval);
}, [slotIndex, kueAlarm1, kueAlarm2, kueCableBreak, kueGroundFault]);
return () => clearInterval(interval); // Bereinigung bei Entladen der Komponente
}, [slotIndex]);
//------------------------------------------------
// Dynamischer Abruf des kueVersion-Werts für jeden Slot in Intervallen
useEffect(() => {
const intervalId = setInterval(() => {
if (window.kueVersion && window.kueVersion[slotIndex]) {
setKueVersion("V" + window.kueVersion[slotIndex] / 100);
}
}, 10000); // 10000 ms = 10 Sekunden
// Bereinigung der Intervalle beim Entfernen der Komponente
return () => clearInterval(intervalId);
}, [slotIndex]);
//-------------------------------------------------
//-------------------------------------------------
// Priority: Aderbruch - Erdschluss - Isolationsfehler - Schleifenfehler - Overflow (>200 MOhm) - Messwert
// Prioritätsprüfung in updateDisplay
useEffect(() => {
const updateDisplay = () => {
if (
!window.kuePSTmMinus96V ||
!window.kueCableBreak ||
!window.kueGroundFault ||
!window.kueAlarm1 ||
!window.kueAlarm2 ||
!window.kueOverflow
) {
// console.log("Warten auf window Variablen...");
setTimeout(updateDisplay, 1000); // Warte 1 Sekunde und versuche es erneut
return;
}
/* console.log(
"Alle window-Variablen sind verfügbar. Beginne mit den Prioritätsprüfungen..."
); */
// PST-M Ausfall
if (window.kuePSTmMinus96V[slotIndex] === 1) {
if (kuePSTmMinus96V?.[slotIndex] === 1) {
setCurrentDisplayValue("PST-M prüfen");
return;
}
// Aderbruch
if (window.kueCableBreak[slotIndex] === 1) {
// console.log("Aderbruch erkannt für Slot", slotIndex);
if (kueCableBreak?.[slotIndex] === 1) {
setCurrentDisplayValue(isoDisplayText);
return;
}
// Erdschluss
else if (window.kueGroundFault[slotIndex] === 1) {
// console.log("Erdschluss erkannt für Slot", slotIndex);
if (kueGroundFault?.[slotIndex] === 1) {
setCurrentDisplayValue(groundFaultDisplayText);
return;
}
// Isolationsfehler
else if (window.kueAlarm1[slotIndex] === 1) {
// console.log("Isolationsfehler erkannt für Slot", slotIndex);
if (kueAlarm1?.[slotIndex] === 1) {
setCurrentDisplayValue(isoFaultDisplayText);
return;
}
// Schleifenfehler
else if (window.kueAlarm2[slotIndex] === 1) {
// console.log("Schleifenfehler erkannt für Slot", slotIndex);
if (kueAlarm2?.[slotIndex] === 1) {
setCurrentDisplayValue(loopFaultDisplayText);
return;
}
// Overflow (>200 MOhm)
else if (window.kueOverflow[slotIndex] === 1) {
/* console.log(
"Overflow erkannt für Slot",
slotIndex,
"- Anzeige: '>200'"
); */
if (kueOverflow?.[slotIndex] === 1) {
setCurrentDisplayValue(isoGreaterThan200);
return;
}
// Kein Fehler
else {
/* console.log(
"Kein Fehler erkannt, zeige Standardisolationswert an für Slot",
slotIndex
); */
setCurrentDisplayValue(isolationswert); // Nur Isolationswert ohne ">200" als Fallback
}
setCurrentDisplayValue(isolationswert);
};
updateDisplay(); // Initialer Aufruf
const interval = setInterval(updateDisplay, 5000); // Regelmäßige Überprüfung
updateDisplay();
const interval = setInterval(updateDisplay, 5000);
return () => clearInterval(interval);
}, [
slotIndex,
isolationswert,
kuePSTmMinus96V,
kueCableBreak,
kueGroundFault,
kueAlarm1,
kueAlarm2,
kueOverflow,
]);
return () => clearInterval(interval); // Bereinigung bei Entladen der Komponente
}, [slotIndex, isolationswert]);
//-------------------------------------------------
useEffect(() => {
if (reduxKueVersion?.[slotIndex]) {
setKueVersion("V" + reduxKueVersion[slotIndex] / 100);
}
}, [slotIndex, reduxKueVersion]);
return (
<div className="relative bg-gray-300 w-[116px] h-[390px] border border-gray-400 scale-110 top-3">
@@ -439,11 +253,8 @@ function Kue705FO({
showModal={showModal}
onClose={handleCloseModal}
slot={slotIndex}
onModulNameChange={handleModulNameChange}
onModulNameChange={setCurrentModulName}
/>
{/*
Bei Kabelbruch (cableBreak), Erdschluss (groundFault), Isolationsfehler (measure1Alarm) oder Schleifenfehler (measure2Alarm)
*/}
<div className="flex flex-col mt-[10px] ml-[10px]">
<div className="flex items-center">
<div className="w-[10px] h-[10px] bg-green-500 rounded-full mr-2"></div>
@@ -452,37 +263,37 @@ function Kue705FO({
<div className="flex items-center mt-1">
<div
className={`w-[10px] h-[10px] rounded-full mr-2 ${
alarmStatus ? "bg-red-500" : "bg-gray-300"
currentAlarmStatus ? "bg-red-500" : "bg-gray-300"
}`}
></div>
<span className="text-white text-[10px]">Alarm</span>
</div>
</div>
{/* Display für Isolationsfehler, Aderbruch, Erdschluss oder Schleifenfehler */}
<div className="relative mt-[50px] mx-auto bg-black text-white w-[100px] h-[40px] flex items-center justify-center text-[18px] z-10">
<div className="text-center">
<span
className={
window.kuePSTmMinus96V[slotIndex] === 1 ||
window.kueCableBreak[slotIndex] === 1 ||
window.kueGroundFault[slotIndex] === 1 ||
window.kueAlarm1[slotIndex] === 1 ||
window.kueAlarm2[slotIndex] === 1
? "text-red-500 text-[14px]" // Rot und kleinere Schrift für Alarme
: window.kueOverflow[slotIndex] === 1 //Sehr hoher Isolationswiderstand , ein sehr gutes Kabel
? "text-white text-[14px]" // Neutrale Farbe für >200 MOhm-Anzeige
kuePSTmMinus96V?.[slotIndex] === 1 ||
kueCableBreak?.[slotIndex] === 1 ||
kueGroundFault?.[slotIndex] === 1 ||
kueAlarm1?.[slotIndex] === 1 ||
kueAlarm2?.[slotIndex] === 1
? "text-red-500 text-[14px]"
: kueOverflow?.[slotIndex] === 1
? "text-white text-[14px]"
: ""
}
>
{currentDisplayValue}
</span>
{window.kuePSTmMinus96V[slotIndex] !== 1 &&
window.kueCableBreak[slotIndex] !== 1 &&
window.kueGroundFault[slotIndex] !== 1 &&
window.kueAlarm1[slotIndex] !== 1 &&
window.kueAlarm2[slotIndex] !== 1 &&
window.kueOverflow[slotIndex] !== 1 && (
{kuePSTmMinus96V?.[slotIndex] !== 1 &&
kueCableBreak?.[slotIndex] !== 1 &&
kueGroundFault?.[slotIndex] !== 1 &&
kueAlarm1?.[slotIndex] !== 1 &&
kueAlarm2?.[slotIndex] !== 1 &&
kueOverflow?.[slotIndex] !== 1 && (
<div className="text-[8px]">ISO MOhm</div>
)}
</div>
@@ -536,13 +347,13 @@ function Kue705FO({
<button
onClick={() => handleButtonClick("TDR")}
className={`w-[50%] h-[25px] text-white text-[10px] flex items-center justify-center ${
window.tdrActive[slotIndex] === 0
tdrActive[slotIndex] === 0
? "bg-gray-200 cursor-not-allowed" // Deaktiviert: Hellgrau
: activeButton === "TDR"
? "bg-littwin-blue" // Aktiviert: Littwin Blau
: "bg-gray-400" // Nicht geklickt: Dunkelgrau
}`}
disabled={window.tdrActive[slotIndex] === 0} // Button deaktiviert, wenn TDR für diesen Slot nicht aktiv ist
disabled={tdrActive[slotIndex] === 0} // Button deaktiviert, wenn TDR für diesen Slot nicht aktiv ist
>
TDR
</button>

View File

@@ -2,232 +2,108 @@
import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import Kue705FO from "../components/modules/Kue705FO";
import { loadWindowVariables } from "../utils/loadWindowVariables";
import { useDispatch, useSelector } from "react-redux";
import { setVariables } from "../store/variablesSlice";
//import { loadWindowVariables } from "../utils/loadWindowVariables";
function Kabelueberwachung() {
const router = useRouter();
const [activeRack, setActiveRack] = useState(1); // Track the active rack
const [kueIso, setKueIso] = useState([]); // State to store isolation values
const [kueID, setKueID] = useState([]); // State to store the KUE names
const [schleifenwiderstand, setSchleifenwiderstand] = useState([]); // State to store the resistance values
const [kueOnline, setKueOnline] = useState([]); // State to store the module status
const [alarmStatus, setAlarmStatus] = useState([]); // State to store the alarm status
const dispatch = useDispatch();
const [activeRack, setActiveRack] = useState(1); // Aktives Rack
const [alarmStatus, setAlarmStatus] = useState([]); // Alarmstatus
// Verwende den useRouter Hook, um den Rack-Parameter zu extrahieren
// Redux-Variablen aus dem Store abrufen
const {
kueOnline,
kueID,
kueIso,
kueAlarm1,
kueAlarm2,
kueRes,
kueCableBreak,
kueGroundFault,
} = useSelector((state) => state.variables);
// URL-Parameter 'rack' abfragen und setzen
useEffect(() => {
const query = new URLSearchParams(window.location.search);
const rackParam = query.get("rack");
if (rackParam) {
setActiveRack(parseInt(rackParam)); // Setze das aktive Rack basierend auf dem URL-Parameter
setActiveRack(parseInt(rackParam));
}
}, [router.query]);
// Load the external JavaScript file and fetch the isolation values
useEffect(() => {
const fetchData = () => {
loadWindowVariables()
.then(() => {
if (window.kueIso && Array.isArray(window.kueIso)) {
setKueIso(window.kueIso);
}
if (window.kueRes && Array.isArray(window.kueRes)) {
setSchleifenwiderstand(window.kueRes);
}
if (window.kueOnline && Array.isArray(window.kueOnline)) {
setKueOnline(window.kueOnline);
}
if (window.kueID && Array.isArray(window.kueID)) {
setKueID(window.kueID);
}
updateAlarmStatus(); // Alarmstatus sofort aktualisieren
})
.catch((error) => {
console.error("Fehler beim Laden der Variablen:", error);
});
// Laden der `window`-Variablen und Speichern in Redux
/* useEffect(() => {
const fetchData = async () => {
const variables = await loadWindowVariables();
dispatch(setVariables(variables));
};
fetchData();
}, [dispatch]);
*/
// Alarmstatus basierend auf Redux-Variablen berechnen
const updateAlarmStatus = () => {
const updatedAlarmStatus = kueIso.map((_, index) => {
return (
(window.kueAlarm1 && window.kueAlarm1[index]) ||
(window.kueAlarm2 && window.kueAlarm2[index]) ||
(window.kueCableBreak && window.kueCableBreak[index]) ||
(window.kueGroundFault && window.kueGroundFault[index])
(kueAlarm1 && kueAlarm1[index]) ||
(kueAlarm2 && kueAlarm2[index]) ||
(kueCableBreak && kueCableBreak[index]) ||
(kueGroundFault && kueGroundFault[index])
);
});
// console.log("Aktualisierter alarmStatus:", updatedAlarmStatus);
setAlarmStatus(updatedAlarmStatus); // State für Alarmstatus aktualisieren
setAlarmStatus(updatedAlarmStatus);
};
fetchData();
const interval = setInterval(fetchData, 10000); // alle 5 Sekunden
// Alarmstatus initial berechnen und alle 10 Sekunden aktualisieren
useEffect(() => {
updateAlarmStatus();
const interval = setInterval(updateAlarmStatus, 10000);
return () => clearInterval(interval);
}, []);
}, [kueIso, kueAlarm1, kueAlarm2, kueCableBreak, kueGroundFault]);
// Zuerst alle Werte der Arrays speichern
// Modul- und Rack-Daten aufbereiten
const allModules = kueIso.map((iso, index) => ({
isolationswert: iso,
schleifenwiderstand: schleifenwiderstand[index],
schleifenwiderstand: kueRes[index],
modulName: kueID[index] || "Unknown",
kueOnlineStatus: kueOnline[index],
alarmStatus: alarmStatus[index],
}));
// Dann die Module für jedes Rack in 8er-Gruppen aufteilen
const racks = {
rack1: allModules.slice(0, 8),
rack2: allModules.slice(8, 16),
rack3: allModules.slice(16, 24),
rack4: allModules.slice(24, 32),
};
// Log the racks in the console for debugging
/* console.log("Rack 1:", racks.rack1);
console.log("Rack 2:", racks.rack2);
console.log("Rack 3:", racks.rack3);
console.log("Rack 4:", racks.rack4); */
// Function to handle rack change
const changeRack = (rack) => {
setActiveRack(rack);
};
// Funktion zum Wechseln des Racks
const changeRack = (rack) => setActiveRack(rack);
useEffect(() => {
const script = document.createElement("script");
const environment = process.env.NEXT_PUBLIC_NODE_ENV || "production";
script.src =
environment === "production"
? "CPL?/CPL/SERVICE/kueData.js"
: "/CPLmockData/SERVICE/kueData.js";
script.async = true;
document.body.appendChild(script);
// Cleanup function mit Überprüfung
return () => {
if (script.parentNode === document.body) {
document.body.removeChild(script);
}
};
}, []);
//----------------------------------------------
useEffect(() => {
const fetchData = () => {
const existingScript = document.querySelector(
"script[src*='kueData.js']"
);
// Stelle sicher, dass das Element existiert und ein Kind von `document.body` ist, bevor du es entfernst
if (existingScript && existingScript.parentNode === document.body) {
document.body.removeChild(existingScript);
}
// Füge das Skript erneut hinzu
const script = document.createElement("script");
script.src =
process.env.NODE_ENV === "production"
? "CPL?/CPL/SERVICE/kueData.js" // Produktionspfad
: "/CPLmockData/SERVICE/kueData.js"; // Entwicklungs-Pfad für Mock-Daten
script.async = true;
script.onload = () => {
// Aktualisiere die Variablen nach kurzer Verzögerung, um sicherzustellen, dass sie geladen sind
setTimeout(() => {
if (window.kueIso && Array.isArray(window.kueIso)) {
setKueIso(window.kueIso);
}
if (window.kueRes && Array.isArray(window.kueRes)) {
setSchleifenwiderstand(window.kueRes);
}
if (window.kueOnline && Array.isArray(window.kueOnline)) {
setKueOnline(window.kueOnline);
}
if (window.kueID && Array.isArray(window.kueID)) {
setKueID(window.kueID);
}
updateAlarmStatus(); // Aktualisiere den Alarmstatus
}, 500); // 500 ms Verzögerung, um sicherzustellen, dass die Daten geladen sind
};
document.body.appendChild(script);
};
const updateAlarmStatus = () => {
const updatedAlarmStatus = window.kueIso.map((_, index) => {
return (
(window.kueAlarm1 && window.kueAlarm1[index]) ||
(window.kueAlarm2 && window.kueAlarm2[index]) ||
(window.kueCableBreak && window.kueCableBreak[index]) ||
(window.kueGroundFault && window.kueGroundFault[index])
);
});
// console.log("Aktualisierter alarmStatus:", updatedAlarmStatus);
setAlarmStatus(updatedAlarmStatus); // Setze den aktualisierten Alarmstatus
};
// Lade die Daten sofort und alle 5 Sekunden neu
fetchData();
const interval = setInterval(fetchData, 10000);
return () => clearInterval(interval); // Bereinige das Intervall beim Entladen der Komponente
}, []);
//----------------------------------------------
return (
<div className="bg-gray-100 flex-1 p-6 text-black">
<h1 className="text-2xl mb-4">Kabelüberwachung</h1>
<div className="mb-4">
{[1, 2, 3, 4].map((rack) => (
<button
onClick={() => changeRack(1)}
className={`mr-1 ${
activeRack === 1
? "bg-littwin-blue text-white p-1 rounded-sm "
: "bg-gray-300 p-1 text-sm"
}`}
>
Rack 1
</button>
<button
onClick={() => changeRack(2)}
key={rack}
onClick={() => changeRack(rack)}
className={`mr-2 ${
activeRack === 2
activeRack === rack
? "bg-littwin-blue text-white p-1 rounded-sm"
: "bg-gray-300 p-1 text-sm"
}`}
>
Rack 2
</button>
<button
onClick={() => changeRack(3)}
className={`mr-2 ${
activeRack === 3
? "bg-littwin-blue text-white p-1 rounded-sm"
: "bg-gray-300 p-1 text-sm"
}`}
>
Rack 3
</button>
<button
onClick={() => changeRack(4)}
className={`mr-2 ${
activeRack === 4
? "bg-littwin-blue text-white p-1 rounded-sm"
: "bg-gray-300 p-1 text-sm"
}`}
>
Rack 4
Rack {rack}
</button>
))}
</div>
<div className="flex flex-row space-x-4 scale-110 ml-[5%] mt-[5%]">
{racks[`rack${activeRack}`].map((slot, index) => {
const slotIndex = index + (activeRack - 1) * 8;
const alarmStatus =
(window.kueAlarm1 && window.kueAlarm1[slotIndex]) ||
(window.kueAlarm2 && window.kueAlarm2[slotIndex]) ||
(window.kueCableBreak && window.kueCableBreak[slotIndex]) ||
(window.kueGroundFault && window.kueGroundFault[slotIndex]);
return (
<div key={index} className="flex">
<Kue705FO
@@ -235,12 +111,9 @@ function Kabelueberwachung() {
schleifenwiderstand={slot.schleifenwiderstand}
modulName={slot.modulName}
kueOnline={slot.kueOnlineStatus}
alarmStatus={alarmStatus} // Pass the calculated alarm status
alarmStatus={slot.alarmStatus}
slotIndex={slotIndex}
/>
{/*
console.log(`Module Data (Rack ${activeRack}, Slot ${index + 1}):`,slot);
*/}
</div>
);
})}

View File

@@ -1,4 +1,4 @@
var last20Messages = `
var win_last20Messages = `
<tr><td>16750</td><td>03501</td><td>2024-10-23 15:08:58:000</td><td>Modul 26 Isofehler kommend</td><td>1</td></tr>
<tr><td>16749</td><td>03201</td><td>2024-10-23 15:07:24:000</td><td>Modul 23 Isofehler gehend</td><td>0</td></tr>
<tr><td>16748</td><td>03501</td><td>2024-10-23 15:01:52:000</td><td>Modul 26 Isofehler gehend</td><td>0</td></tr>

View File

@@ -1,17 +1,17 @@
var appVersion = "0.02";
var deviceName = "CPLV4_Maschen";
var mac1 = "0 48 86 81 46 143";
var mac2 = "0 48 86 81 46 144";
var ip = "10.10.0.243";
var subnet = "255.255.255.0";
var gateway = "10.10.0.1";
var datetime = "23.10.24 15:10:28 Uhr";
var opcState = "1";
var opcSessions = "0";
var win_appVersion = "0.02";
var win_deviceName = "CPLV4_Maschen";
var win_mac1 = "0 48 86 81 46 143";
var win_mac2 = "0 48 86 81 46 144";
var win_ip = "10.10.0.243";
var win_subnet = "255.255.255.0";
var win_gateway = "10.10.0.1";
var win_datetime = "23.10.24 15:10:28 Uhr";
var win_opcState = "1";
var win_opcSessions = "0";
//var opcName="CPL V4 OPC UA Application Deutsche Bahne']'])";
var opcName = "CPL V4 OPC UA Application Deutsche Bahne";
var ntp1 = "192.53.103.108";
var ntp2 = "0.0.0.0";
var ntp3 = "0.0.0.0";
var ntpTimezone = "2";
var ntpActive = "1";
var win_opcName = "CPL V4 OPC UA Application Deutsche Bahne";
var win_ntp1 = "192.53.103.108";
var win_ntp2 = "0.0.0.0";
var win_ntp3 = "0.0.0.0";
var win_ntpTimezone = "2";
var win_ntpActive = "1";

View File

@@ -1,3 +1,13 @@
var de=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var counter=[0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000];
var flutter=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var win_de = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
var win_counter = [
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0,
];
var win_flutter = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];

View File

@@ -1,5 +1,5 @@
//Modul vorhanden 1 = vorhanden, 0 = nicht vorhanden
var kueOnline = [
var win_kueOnline = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
];
@@ -8,44 +8,44 @@ var kueOnline = [
/*
Das kann sein, muss aber nicht. Hier unten im Testaufbau haben wir nur eine PST-M für alle 32 Kabelüberwachungen. Es kann aber sein das beim Kunden auch für jeden BGT eine PST-M vorhanden ist, also insgesamt 4 Stück.
*/
var kuePSTmMinus96V = [
var win_kuePSTmMinus96V = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
//Aderbruch 1 = Fehler, 0 = kein Fehler
var kueCableBreak = [
var win_kueCableBreak = [
1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 1,
];
//Erdschluss 1 = Fehler, 0 = kein Fehler
var kueGroundFault = [
var win_kueGroundFault = [
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
//Isolationsfehler 1 = Fehler, 0 = kein Fehler, Alarm kommt wenn kueIso < kueLimit1
var kueAlarm1 = [
var win_kueAlarm1 = [
1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0,
];
//Schleifenfehler 1 = Fehler, 0 = kein Fehler
var kueAlarm2 = [
var win_kueAlarm2 = [
1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0,
];
//Überlauf 1 = Fehler, 0 = kein Fehler , hier wird in Display ">200 MOhm" angezeigt
var kueOverflow = [
var win_kueOverflow = [
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
//---------------------------------------------------
//Isolationswerte in Display (isoDisplay) Einheit: MOhm
var kueIso = [
var win_kueIso = [
10.0, 10.0, 10.0, 10.5, 10.0, 10.0, 10.0, 10.0, 10.5, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.5, 10.0, 10.0, 10.0, 10.0, 10.0,
10.5, 10.0, 200.0, 200.0, 200.0, 200.0,
];
//Grenzwert (MOhm) für Isolationswiderstand
var kueLimit1 = [
var win_kueLimit1 = [
9, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
@@ -60,40 +60,40 @@ Wenn der Widerstand innerhalb dieser 420 Sekunden wieder über den Grenzwert ste
die Filterzeit startet beim nächsten Unterschreiten des Grenzwerts neu. Die Filterzeit verhindert also, dass
kurzfristige Schwankungen oder Störungen fälschlicherweise als Fehler gemeldet werden.
*/
var kueDelay1 = [
var win_kueDelay1 = [
10, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
420,
];
//---------------------------------------------------
//Schleifenwiderstand in Display (resDisplay) Einheit: KOhm
var kueRes = [
var win_kueRes = [
0.0, 0.612, 0.0, 0.645, 0.822, 0.97, 0.0, 0.0, 1.452, 0.0, 0.734, 0.37, 0.566,
0.0, 0.738, 0.684, 1.166, 0.595, 0.0, 1.651, 1.18, 1.387, 1.214, 0.0, 1.475,
0.615, 0.494, 1.217, 65.0, 65.0, 65.0, 65.0,
];
//Schleifenmessung Unterer Grenzwert (KOhm)
var kueLimit2Low = [
var win_kueLimit2Low = [
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1,
];
//Schleifenintervall (h) für Schleifenmessung
var kueLoopInterval = [
var win_kueLoopInterval = [
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6,
];
//---------------------------------------------------
//KÜ Modul Version soll /100 und davor V angezeigt werden z.B. 4.19V
var kueVersion = [
var win_kueVersion = [
419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419,
419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419, 419,
419, 419,
];
//Modulname in Komponente und auf der Anzeige
var kueID = [
var win_kueID = [
"FTZ_2",
"B23",
"Kabel 3",
@@ -130,43 +130,43 @@ var kueID = [
//---------------------------------------------------
var kueResidence = [
var win_kueResidence = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
//TDR---------------------------------------------------
var tdrAtten = [
var win_tdrAtten = [
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
2.0, 2.0,
];
var tdrPulse = [
var win_tdrPulse = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
var tdrSpeed = [
var win_tdrSpeed = [
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100,
];
var tdrAmp = [
var win_tdrAmp = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
var tdrTrigger = [
var win_tdrTrigger = [
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80,
];
var tdrLocation = [
var win_tdrLocation = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
var tdrActive = [
var win_tdrActive = [
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
];
var tdrLast = [
var win_tdrLast = [
"2024-10-17 07:51:54:000",
"2024-09-30 08:38:50:000",
"?",

View File

@@ -13,7 +13,7 @@ const initialState = {
ntp1: null,
ntp2: null,
ntp3: null,
zeitzone: null,
ntpTimezone: null,
ntpActive: null,
de: null,
counter: null,

View File

@@ -2,46 +2,47 @@
export async function loadWindowVariables() {
return new Promise((resolve, reject) => {
const requiredVars = [
"last20Messages",
"deviceName",
"mac1",
"mac2",
"ip",
"subnet",
"gateway",
"datetime",
"ntp1",
"ntp2",
"ntp3",
"systemZeit",
"ntpTimezone",
"ntpActive",
"de",
"counter",
"flutter",
"kueOnline",
"kueID",
"kueAlarm1",
"kueAlarm2",
"kueRes",
"kueCableBreak",
"kueGroundFault",
"kueLimit1",
"kueLimit2Low",
"kueDelay1",
"kueLoopInterval",
"kueVersion",
"tdrAtten",
"tdrPulse",
"tdrSpeed",
"tdrAmp",
"tdrTrigger",
"tdrLocation",
"tdrActive",
"kueOverflow",
"kueResidence",
"tdrLast",
"appVersion",
"win_last20Messages",
"win_deviceName",
"win_mac1",
"win_mac2",
"win_ip",
"win_subnet",
"win_gateway",
"win_datetime",
"win_ntp1",
"win_ntp2",
"win_ntp3",
"win_systemZeit",
"win_ntpTimezone",
"win_ntpActive",
"win_de",
"win_counter",
"win_flutter",
"win_kueOnline",
"win_kueID",
"win_kueAlarm1",
"win_kueAlarm2",
"win_kueIso",
"win_kueRes",
"win_kueCableBreak",
"win_kueGroundFault",
"win_kueLimit1",
"win_kueLimit2Low",
"win_kueDelay1",
"win_kueLoopInterval",
"win_kueVersion",
"win_tdrAtten",
"win_tdrPulse",
"win_tdrSpeed",
"win_tdrAmp",
"win_tdrTrigger",
"win_tdrLocation",
"win_tdrActive",
"win_kueOverflow",
"win_kueResidence",
"win_tdrLast",
"win_appVersion",
];
const loadScript = (src) => {
@@ -69,7 +70,7 @@ export async function loadWindowVariables() {
.then(() => {
const variablesObj = requiredVars.reduce((acc, variable) => {
if (window[variable] !== undefined) {
acc[variable] = window[variable];
acc[variable.replace("win_", "")] = window[variable]; // Entferne "win_" beim Speichern in Redux
}
return acc;
}, {});