mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-17 01:50:47 -04:00
elidarea
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const { spawn } = require('child_process');
|
const { spawn, spawnSync } = require('child_process');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@@ -11,10 +11,6 @@ function sanitizeLogText(value) {
|
|||||||
.replace(/\x1B\[[0-9;]*[A-Za-z]/g, '');
|
.replace(/\x1B\[[0-9;]*[A-Za-z]/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function shellQuote(value) {
|
|
||||||
return `'${String(value || '').replace(/'/g, `'\"'\"'`)}'`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parsePayloadFromLine(line) {
|
function parsePayloadFromLine(line) {
|
||||||
const raw = sanitizeLogText(line).trim();
|
const raw = sanitizeLogText(line).trim();
|
||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
@@ -268,30 +264,38 @@ function createLidarRuntime({ logger, host, port = 6053, key, logFile = '', shou
|
|||||||
if (state.process) return;
|
if (state.process) return;
|
||||||
ensureLogStream();
|
ensureLogStream();
|
||||||
|
|
||||||
const baseCommand = [
|
logger.info('Starting Neato lidar log stream', { host, port: Number(port || 6053) });
|
||||||
'env',
|
const env = {
|
||||||
'PYTHONUNBUFFERED=1',
|
...process.env,
|
||||||
'NO_COLOR=1',
|
PYTHONUNBUFFERED: '1',
|
||||||
'TERM=dumb',
|
NO_COLOR: '1',
|
||||||
'uvx',
|
TERM: 'dumb',
|
||||||
|
};
|
||||||
|
const uvxArgs = [
|
||||||
'--from',
|
'--from',
|
||||||
'aioesphomeapi',
|
'aioesphomeapi',
|
||||||
'aioesphomeapi-logs',
|
'aioesphomeapi-logs',
|
||||||
shellQuote(host),
|
host,
|
||||||
'--port',
|
'--port',
|
||||||
shellQuote(String(port || 6053)),
|
String(port || 6053),
|
||||||
'--noise-psk',
|
'--noise-psk',
|
||||||
shellQuote(key),
|
key,
|
||||||
'--no-states',
|
'--no-states',
|
||||||
].join(' ');
|
];
|
||||||
const launchCommand = `if command -v script >/dev/null 2>&1; then exec script -qefc ${shellQuote(baseCommand)} /dev/null; else exec ${baseCommand}; fi`;
|
const hasScript = spawnSync('bash', ['-lc', 'command -v script >/dev/null 2>&1'], { stdio: 'ignore' }).status === 0;
|
||||||
|
const proc = hasScript
|
||||||
logger.info('Starting Neato lidar log stream', { host, port: Number(port || 6053) });
|
? spawn('script', ['-qefc', `uvx ${uvxArgs.map((arg) => JSON.stringify(arg)).join(' ')}`, '/dev/null'], {
|
||||||
const proc = spawn('bash', ['-lc', launchCommand], {
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
env,
|
||||||
});
|
})
|
||||||
|
: spawn('uvx', uvxArgs, {
|
||||||
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
logger.info('Neato lidar log launch mode', { mode: hasScript ? 'script' : 'direct' });
|
||||||
state.process = proc;
|
state.process = proc;
|
||||||
state.stdoutBuffer = '';
|
state.stdoutBuffer = '';
|
||||||
|
state.stderrBuffer = '';
|
||||||
|
|
||||||
proc.stdout.on('data', (chunk) => {
|
proc.stdout.on('data', (chunk) => {
|
||||||
if (!state.connected) {
|
if (!state.connected) {
|
||||||
|
|||||||
Reference in New Issue
Block a user