feat: local-cpl-sim.mjs digitalInputs /Messwerteingänge
This commit is contained in:
@@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
|
|||||||
NEXT_PUBLIC_EXPORT_STATIC=false
|
NEXT_PUBLIC_EXPORT_STATIC=false
|
||||||
NEXT_PUBLIC_USE_CGI=false
|
NEXT_PUBLIC_USE_CGI=false
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.6.837
|
NEXT_PUBLIC_APP_VERSION=1.6.838
|
||||||
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
||||||
|
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL
|
|||||||
NEXT_PUBLIC_EXPORT_STATIC=true
|
NEXT_PUBLIC_EXPORT_STATIC=true
|
||||||
NEXT_PUBLIC_USE_CGI=true
|
NEXT_PUBLIC_USE_CGI=true
|
||||||
# App-Versionsnummer
|
# App-Versionsnummer
|
||||||
NEXT_PUBLIC_APP_VERSION=1.6.837
|
NEXT_PUBLIC_APP_VERSION=1.6.838
|
||||||
NEXT_PUBLIC_CPL_MODE=production
|
NEXT_PUBLIC_CPL_MODE=production
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
## [1.6.838] – 2025-09-04
|
||||||
|
|
||||||
|
- feat: local-cpl-sim system
|
||||||
|
|
||||||
|
---
|
||||||
## [1.6.837] – 2025-09-04
|
## [1.6.837] – 2025-09-04
|
||||||
|
|
||||||
- feat: local-cpl-sim meldungen/Berichte
|
- feat: local-cpl-sim meldungen/Berichte
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.837",
|
"version": "1.6.838",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.837",
|
"version": "1.6.838",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^5.1.0",
|
"@fontsource/roboto": "^5.1.0",
|
||||||
"@headlessui/react": "^2.2.4",
|
"@headlessui/react": "^2.2.4",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cpl-v4",
|
"name": "cpl-v4",
|
||||||
"version": "1.6.837",
|
"version": "1.6.838",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3000",
|
"dev": "next dev -p 3000",
|
||||||
|
|||||||
@@ -14,6 +14,30 @@ const ROOT = path.join(process.cwd(), "out");
|
|||||||
const textCache = new Map(); // key: absolute path, value: { mtimeMs, body, contentType }
|
const textCache = new Map(); // key: absolute path, value: { mtimeMs, body, contentType }
|
||||||
let messagesAllCache = null; // cache parsed meldungen/messages_all.json
|
let messagesAllCache = null; // cache parsed meldungen/messages_all.json
|
||||||
|
|
||||||
|
// Helper to read JSON body from POST requests
|
||||||
|
function readRequestBody(req) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let data = "";
|
||||||
|
req.on("data", (chunk) => {
|
||||||
|
data += chunk;
|
||||||
|
// Basic guard against huge bodies in local dev
|
||||||
|
if (data.length > 1_000_000) {
|
||||||
|
req.destroy();
|
||||||
|
reject(new Error("Request body too large"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.on("end", () => {
|
||||||
|
try {
|
||||||
|
const json = data ? JSON.parse(data) : {};
|
||||||
|
resolve(json);
|
||||||
|
} catch {
|
||||||
|
resolve({});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
req.on("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function exists(p) {
|
function exists(p) {
|
||||||
try {
|
try {
|
||||||
fs.accessSync(p, fs.constants.F_OK);
|
fs.accessSync(p, fs.constants.F_OK);
|
||||||
@@ -453,7 +477,7 @@ function notFound(res) {
|
|||||||
res.end("Not Found");
|
res.end("Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer(async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(req.url, `http://localhost:${PORT}`);
|
const url = new URL(req.url, `http://localhost:${PORT}`);
|
||||||
const pathname = decodeURIComponent(url.pathname);
|
const pathname = decodeURIComponent(url.pathname);
|
||||||
@@ -501,6 +525,106 @@ const server = http.createServer((req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dev API: digital inputs getter used by exported app on localhost
|
||||||
|
if (pathname === "/api/cpl/getDigitalInputsHandler") {
|
||||||
|
try {
|
||||||
|
const p = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
"mocks",
|
||||||
|
"device-cgi-simulator",
|
||||||
|
"SERVICE",
|
||||||
|
"digitalInputsMockData.json"
|
||||||
|
);
|
||||||
|
const raw = fs.readFileSync(p, "utf8");
|
||||||
|
res.writeHead(200, {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
});
|
||||||
|
res.end(raw);
|
||||||
|
} catch {
|
||||||
|
res.writeHead(500, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Interner Serverfehler" }));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dev API: digital inputs updater used by UI Save button in dev/exported mode
|
||||||
|
if (pathname === "/api/cpl/updateDigitalInputs") {
|
||||||
|
if (req.method !== "POST") {
|
||||||
|
res.writeHead(405, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Only POST supported" }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const body = await readRequestBody(req);
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
invert,
|
||||||
|
timeFilter,
|
||||||
|
weighting,
|
||||||
|
zaehlerAktiv,
|
||||||
|
eingangOffline,
|
||||||
|
} = body || {};
|
||||||
|
if (typeof id !== "number" || id < 1 || id > 32) {
|
||||||
|
res.writeHead(400, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Ungültige ID (1–32 erlaubt)" }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fp = path.join(
|
||||||
|
process.cwd(),
|
||||||
|
"mocks",
|
||||||
|
"device-cgi-simulator",
|
||||||
|
"SERVICE",
|
||||||
|
"digitalInputsMockData.json"
|
||||||
|
);
|
||||||
|
const current = JSON.parse(fs.readFileSync(fp, "utf8"));
|
||||||
|
const idx = id - 1;
|
||||||
|
if (typeof label === "string" && Array.isArray(current.win_de_label))
|
||||||
|
current.win_de_label[idx] = label;
|
||||||
|
if (typeof invert === "number" && Array.isArray(current.win_de_invert))
|
||||||
|
current.win_de_invert[idx] = invert;
|
||||||
|
if (
|
||||||
|
typeof timeFilter === "number" &&
|
||||||
|
Array.isArray(current.win_de_time_filter)
|
||||||
|
)
|
||||||
|
current.win_de_time_filter[idx] = timeFilter;
|
||||||
|
if (
|
||||||
|
typeof weighting === "number" &&
|
||||||
|
Array.isArray(current.win_de_weighting)
|
||||||
|
)
|
||||||
|
current.win_de_weighting[idx] = weighting;
|
||||||
|
if (
|
||||||
|
typeof zaehlerAktiv === "number" &&
|
||||||
|
Array.isArray(current.win_de_counter_active)
|
||||||
|
)
|
||||||
|
current.win_de_counter_active[idx] = zaehlerAktiv;
|
||||||
|
if (
|
||||||
|
typeof eingangOffline === "number" &&
|
||||||
|
Array.isArray(current.win_de_offline)
|
||||||
|
)
|
||||||
|
current.win_de_offline[idx] = eingangOffline;
|
||||||
|
|
||||||
|
fs.writeFileSync(fp, JSON.stringify(current, null, 2), "utf8");
|
||||||
|
res.writeHead(200, { "Content-Type": "application/json" });
|
||||||
|
res.end(
|
||||||
|
JSON.stringify({
|
||||||
|
message: `Update erfolgreich für ID ${id}`,
|
||||||
|
id,
|
||||||
|
label,
|
||||||
|
invert,
|
||||||
|
timeFilter,
|
||||||
|
weighting,
|
||||||
|
eingangOffline,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
res.writeHead(500, { "Content-Type": "application/json" });
|
||||||
|
res.end(JSON.stringify({ error: "Update fehlgeschlagen" }));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// CPL? mapping: /CPL?/CPL/... -> /CPL/... and service commands
|
// CPL? mapping: /CPL?/CPL/... -> /CPL/... and service commands
|
||||||
if (pathname === "/CPL" && rawQuery) {
|
if (pathname === "/CPL" && rawQuery) {
|
||||||
const q = decodeURIComponent(rawQuery);
|
const q = decodeURIComponent(rawQuery);
|
||||||
|
|||||||
Reference in New Issue
Block a user