feat: jsSimulatedProd-Modus für analoge & digitale Eingänge implementiert
- neuen Modus `jsSimulatedProd` eingeführt für realitätsnahe Simulation auf Basis echter Produktionsdaten - analoge Eingänge: analogInputsMockData.js eingebunden und dynamisch per Script geladen - digitale Eingänge: digitalInputsMockData.js eingebunden mit window-Variablen (z. B. win_de_state, win_de_label etc.) - fetchAnalogInputsService.ts und fetchDigitalInputsService.ts angepasst zur Modusprüfung und Script-Auswertung - getAnalogInputsHandler.ts und getDigitalInputsHandler.ts geben im jsSimulatedProd-Modus JavaScript-Dateien aus - .env.development setzt `NEXT_PUBLIC_CPL_MODE=jsSimulatedProd`
This commit is contained in:
@@ -38,7 +38,7 @@ export async function fetchAnalogInputsHistoryService(): Promise<
|
||||
const data = await response.json();
|
||||
|
||||
// 🔍 Log: JSON anzeigen
|
||||
console.log("✅ [DEV] Parsed JSON:", data);
|
||||
//console.log("✅ [DEV] Parsed JSON:", data);
|
||||
|
||||
// 🔍 Validitätsprüfung (optional)
|
||||
JSON.stringify(data); // Wenn das fehlschlägt, wird catch ausgelöst
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
export const fetchAnalogInputsService = async () => {
|
||||
const mode = process.env.NEXT_PUBLIC_CPL_MODE;
|
||||
|
||||
// ✅ PRODUKTIV: lädt JavaScript vom Gerät über CGI
|
||||
if (mode === "production") {
|
||||
console.log("🔄 Lade analoge Eingänge im Produktionsmodus...");
|
||||
const scriptUrl = "/CPL?/CPL/SERVICE/analogInputs.js";
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
@@ -27,7 +28,38 @@ export const fetchAnalogInputsService = async () => {
|
||||
loggerInterval: parseInt(win.win_analogInputsLoggerIntervall[i]),
|
||||
weighting: parseInt(win.win_analogInputsWeighting[i]),
|
||||
}));
|
||||
} else if (mode === "json" || mode === "jsmock") {
|
||||
}
|
||||
// ✅ jsSimulatedProd-MODUS (Script einbinden und aus window lesen)
|
||||
else if (mode === "jsSimulatedProd") {
|
||||
console.log("🔄 Lade simulierte analoge Eingänge im Produktionsmodus...");
|
||||
const scriptUrl = "/api/cpl/getAnalogInputsHandler"; // gibt JavaScript zurück
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = scriptUrl;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () =>
|
||||
reject("❌ Fehler beim Laden des simulierten Scripts");
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
const win = window as any;
|
||||
|
||||
return Array.from({ length: 8 }, (_, i) => ({
|
||||
id: i + 1,
|
||||
value: parseFloat(win.win_analogInputsValues[i]),
|
||||
label: win.win_analogInputsLabels[i],
|
||||
unit: win.win_analogInputsUnits[i],
|
||||
offset: parseFloat(win.win_analogInputsOffset[i]),
|
||||
factor: parseFloat(win.win_analogInputsFactor[i]),
|
||||
loggerInterval: parseInt(win.win_analogInputsLoggerIntervall[i]),
|
||||
weighting: parseInt(win.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");
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ export const fetchDigitalInputsService = async () => {
|
||||
|
||||
// ✅ PRODUKTIV: lädt JavaScript vom Gerät über CGI
|
||||
if (mode === "production") {
|
||||
console.log("🔄 Lade analoge Eingänge im Produktionsmodus...");
|
||||
const scriptUrl = "/CPL?/CPL/SERVICE/digitalInputs.js";
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
@@ -34,7 +35,8 @@ export const fetchDigitalInputsService = async () => {
|
||||
}
|
||||
|
||||
// ✅ JSON-MODUS (API gibt JSON-Daten zurück)
|
||||
if (mode === "json") {
|
||||
else if (mode === "json") {
|
||||
console.log("🔄 Lade digitale Eingänge im JSON-Modus...");
|
||||
const res = await fetch("/api/cpl/getDigitalInputsHandler");
|
||||
if (!res.ok)
|
||||
throw new Error("❌ Fehler beim Laden der digitalen Eingänge (json)");
|
||||
@@ -55,14 +57,38 @@ export const fetchDigitalInputsService = async () => {
|
||||
}));
|
||||
}
|
||||
|
||||
// ✅ JSMOCK-MODUS (Script einbinden und aus window lesen)
|
||||
if (mode === "jsmock") {
|
||||
const res = await fetch("/api/cpl/getDigitalInputsHandler");
|
||||
if (!res.ok)
|
||||
throw new Error("❌ Fehler beim Laden der digitalen Eingänge (json)");
|
||||
// ✅ jsSimulatedProd-MODUS (Script einbinden und aus window lesen)
|
||||
else if (mode === "jsSimulatedProd") {
|
||||
console.log("🔄 Lade digitale Eingänge im jsSimulatedProd-Modus...");
|
||||
// const res = await fetch("/api/cpl/getDigitalInputsHandler");
|
||||
//------------------------
|
||||
const scriptUrl = "/api/cpl/getDigitalInputsHandler"; // gibt JavaScript zurück
|
||||
|
||||
const data = await res.json();
|
||||
console.log("📡 JSMOCK-Daten geladen in service:", data);
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = scriptUrl;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () =>
|
||||
reject("❌ Fehler beim Laden des simulierten Scripts");
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
// Annahme: Das Script setzt window.win_de_state usw.
|
||||
const data = {
|
||||
win_de_state: (window as any).win_de_state,
|
||||
win_de_label: (window as any).win_de_label,
|
||||
win_de_invert: (window as any).win_de_invert,
|
||||
win_de_counter: (window as any).win_de_counter,
|
||||
win_de_time_filter: (window as any).win_de_time_filter,
|
||||
win_de_weighting: (window as any).win_de_weighting,
|
||||
win_de_counter_active: (window as any).win_de_counter_active,
|
||||
win_de_offline: (window as any).win_de_offline,
|
||||
};
|
||||
|
||||
//--------------------------
|
||||
|
||||
console.log("📡 jsSimulatedProd-Daten geladen in service:", data);
|
||||
|
||||
return data.win_de_state.map((_: any, i: number) => ({
|
||||
id: i + 1,
|
||||
|
||||
@@ -33,7 +33,7 @@ export const fetchDigitalOutputsService = async () => {
|
||||
status: status === 1,
|
||||
}));
|
||||
}
|
||||
} else if (mode === "json" || mode === "jsmock") {
|
||||
} else if (mode === "json" || mode === "jsSimulatedProd") {
|
||||
const res = await fetch("/api/cpl/getDigitalOutputsHandler");
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user