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:
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user