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:
@@ -20,39 +20,14 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return res.status(200).json(json);
|
||||
}
|
||||
|
||||
if (mode === "jsmock") {
|
||||
const jsPath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalInputsMockData.js"
|
||||
if (mode === "jsSimulatedProd") {
|
||||
const analogInputsScript = fs.readFileSync(
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalInputsMockData.js",
|
||||
"utf-8"
|
||||
);
|
||||
const fileContent = fs.readFileSync(jsPath, "utf-8");
|
||||
//console.log("📡 JSMOCK-Daten geladen fileContent:", fileContent);
|
||||
|
||||
const extractArray = (label: string) => {
|
||||
const match = fileContent.match(
|
||||
new RegExp(`var\\s+${label}\\s*=\\s*\\[([\\s\\S]*?)\\];`)
|
||||
);
|
||||
if (!match) throw new Error(`Feld ${label} nicht gefunden`);
|
||||
return match[1]
|
||||
.split(",")
|
||||
.map((s) => s.trim().replace(/^["']|["']$/g, ""));
|
||||
};
|
||||
|
||||
const data = {
|
||||
win_de_state: extractArray("win_de_state").map(Number),
|
||||
win_de_invert: extractArray("win_de_invert").map(Number),
|
||||
win_de_counter: extractArray("win_de_counter").map(Number),
|
||||
win_de_time_filter: extractArray("win_de_time_filter").map(Number),
|
||||
win_de_weighting: extractArray("win_de_weighting").map(Number),
|
||||
win_de_counter_active: extractArray("win_de_counter_active").map(
|
||||
Number
|
||||
),
|
||||
win_de_offline: extractArray("win_de_offline").map(Number),
|
||||
win_de_label: extractArray("win_de_label"),
|
||||
};
|
||||
//console.log("📡 JSMOCK-Daten geladen in api in jsmock:", data);
|
||||
|
||||
return res.status(200).json(data);
|
||||
res.setHeader("Content-Type", "application/javascript");
|
||||
res.status(200).send(analogInputsScript);
|
||||
return;
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Ungültiger Modus" });
|
||||
|
||||
Reference in New Issue
Block a user