feat: Digitale Ausgänge vollständig implementiert (Lesen & Schreiben in allen Modi)
- Unterstützung für drei Modi implementiert: json, jsmock und production - fetchDigitalOutputsService.ts erkennt NEXT_PUBLIC_CPL_MODE und lädt Daten je nach Umgebung - API-Handler /api/cpl/updateDigitalOutputsHandler verarbeitet POST-Anfragen für json und jsmock - In production wird Statusänderung per Redirect (window.location.href) an das CPL gesendet - Redux-Slice für digitale Ausgänge vollständig angebunden - UI (DigitalOutputsWidget.tsx) zeigt Status und ermöglicht das Umschalten - Dokumentation als README_digitalOutputs_final.md mit UML-Diagrammen ergänzt - CHANGELOG.md auf Version 1.6.417 aktualisiert
This commit is contained in:
48
pages/api/fake-cpl/SERVICE/updateDigitalOutputsHandler.ts
Normal file
48
pages/api/fake-cpl/SERVICE/updateDigitalOutputsHandler.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// /pages/api/fake-cpl/SERVICE/updateDigitalOutputsHandler.ts
|
||||
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET erlaubt" });
|
||||
}
|
||||
|
||||
const id = parseInt(req.query.id as string);
|
||||
const value = parseInt(req.query.value as string);
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks",
|
||||
"device-cgi-simulator",
|
||||
"SERVICE",
|
||||
"digitalOutputsMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
let content = fs.readFileSync(filePath, "utf-8");
|
||||
|
||||
const match = content.match(/win_da_state\s*=\s*\[(.*?)\];/s);
|
||||
const currentState = match ? JSON.parse(`[${match[1]}]`) : [];
|
||||
|
||||
if (isNaN(id) || isNaN(value) || id < 1 || id > currentState.length) {
|
||||
return res
|
||||
.status(400)
|
||||
.json({ error: `Ungültige Parameter: id=${id}, value=${value}` });
|
||||
}
|
||||
|
||||
// Wert aktualisieren
|
||||
currentState[id - 1] = value;
|
||||
|
||||
const updatedContent =
|
||||
`win_da_state = [${currentState.join(", ")}];\n` +
|
||||
`win_da_bezeichnung = ["A1", "A2", "A3", "A4"]; // fest für Demo`;
|
||||
|
||||
fs.writeFileSync(filePath, updatedContent, "utf-8");
|
||||
|
||||
res.status(200).json({ success: true, win_da_state: currentState });
|
||||
} catch (err) {
|
||||
console.error("❌ Fehler beim Schreiben der Mock-Datei:", err);
|
||||
res.status(500).json({ error: "Fehler beim Schreiben der Mock-Datei" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user