Emergency Stop

This commit is contained in:
chk
2026-06-12 18:16:15 +02:00
parent 6fc6605080
commit 59d4cf7df4
17 changed files with 1098 additions and 540 deletions

View File

@@ -3,6 +3,7 @@ const https = require('https');
const { createRobotFromEnv } = require('./robot/KinematicsFactory');
const GCode = require('./robot/GCode');
const TelnetSender = require('./robot/TelnetSenderGRBL');
const ShellySender = require('./robot/ShellyEmergencyStop');
const RobotConfig = require('./robot/RobotConfig');
const initInputWS = require('./server/InputWS');
@@ -47,6 +48,7 @@ function createApp(options = {}) {
RobotClass = null,
GCodeModule = GCode,
TelnetSenderClass = TelnetSender,
ShellyClass = ShellySender,
initInputWSFn = initInputWS,
createInfoServerFn = createInfoServer,
setTimeoutFn = setTimeout,
@@ -93,16 +95,22 @@ function createApp(options = {}) {
for (const [key, ctrl] of Object.entries(cfg.controllers)) {
const name = key.charAt(0).toUpperCase() + key.slice(1);
// Konstruktor erwartet 7 Achsen-Slots (x y z a b c e) vor dem Options-Objekt.
// Auf genau 7 auffüllen, damit heartbeatInterval nicht als Achsen-Arg landet.
const axes7 = [...(ctrl.axes ?? [])];
while (axes7.length < 7) axes7.push(null);
const instance = new TelnetSenderClass(ctrl.ip, ctrl.port, ...axes7, {
heartbeatInterval: ctrl.heartbeatInterval,
deadTimeout: 2 * ctrl.heartbeatInterval,
});
senders.push({ name, instance });
if (ctrl.protocol === 'shelly') {
// Shelly Smart Plug: kein GCode-Empfänger, nur Emergency-Stop-Aktor
const instance = new ShellyClass(ctrl.url);
senders.push({ name, instance, isGCodeReceiver: false });
} else {
// Telnet (FluidNC): Konstruktor erwartet 7 Achsen-Slots (x y z a b c e) vor dem
// Options-Objekt. Auf genau 7 auffüllen, damit heartbeatInterval nicht als
// Achsen-Arg landet.
const axes7 = [...(ctrl.axes ?? [])];
while (axes7.length < 7) axes7.push(null);
const instance = new TelnetSenderClass(ctrl.ip, ctrl.port, ...axes7, {
heartbeatInterval: ctrl.heartbeatInterval,
deadTimeout: 2 * ctrl.heartbeatInterval,
});
senders.push({ name, instance, isGCodeReceiver: true });
}
}
startupStatus.senders = senders.map(getSenderConnectionStatus);
@@ -111,13 +119,9 @@ function createApp(options = {}) {
consoleObj.warn(`Startup warning: ${disconnectedSenders.length} sender(s) disconnected at startup.`);
}
// Register all senders as command receivers immediately and permanently.
// Each sender's execCommand() guards internally against sending while it is
// disconnected, and resumes automatically once it (re)connects — so there is
// no need to wait for a socket or to re-register after a reconnect. The old
// 5s one-shot registration silently dropped senders that connected later
// (e.g. after EHOSTUNREACH backoff) and never registered WebSocket senders.
senders.forEach(s => robot.cmdReceivers.push(s.instance));
// Nur Telnet-Sender (FluidNC) empfangen GCode — Shelly wird ausgeschlossen.
// Jeder Sender reconnectet automatisch, daher sofortige Registrierung ohne Delay.
senders.filter(s => s.isGCodeReceiver).forEach(s => robot.cmdReceivers.push(s.instance));
const port = Number(processEnv.PORT) || 2095;
httpsServer.listen(port);