mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
brainslug logfile
This commit is contained in:
@@ -42,6 +42,8 @@ homeAssistant:
|
|||||||
brainslugHost: "neato-vacuum.local"
|
brainslugHost: "neato-vacuum.local"
|
||||||
brainslugPort: 6053
|
brainslugPort: 6053
|
||||||
brainslugKey: "REPLACE_WITH_ESPHOME_NOISE_PSK"
|
brainslugKey: "REPLACE_WITH_ESPHOME_NOISE_PSK"
|
||||||
|
# Optional: mirror raw ESPHome lidar log output to a local file for debugging.
|
||||||
|
brainslugLogFile: "/tmp/brainslug-lidar.log"
|
||||||
lift:
|
lift:
|
||||||
# Two Home Assistant switches controlling lift direction.
|
# Two Home Assistant switches controlling lift direction.
|
||||||
# Raise sequence: down off -> wait interlockMs -> up on
|
# Raise sequence: down off -> wait interlockMs -> up on
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const RESUME_DELAY_MS = 3000;
|
|||||||
const brainslugHost = String(neatoConfig.brainslugHost || '').trim();
|
const brainslugHost = String(neatoConfig.brainslugHost || '').trim();
|
||||||
const brainslugPort = Number(neatoConfig.brainslugPort) || 6053;
|
const brainslugPort = Number(neatoConfig.brainslugPort) || 6053;
|
||||||
const brainslugKey = String(neatoConfig.brainslugKey || '').trim();
|
const brainslugKey = String(neatoConfig.brainslugKey || '').trim();
|
||||||
|
const brainslugLogFile = String(neatoConfig.brainslugLogFile || '').trim();
|
||||||
let lidarRuntime = null;
|
let lidarRuntime = null;
|
||||||
|
|
||||||
function entityId(domain, suffix) {
|
function entityId(domain, suffix) {
|
||||||
@@ -281,6 +282,7 @@ lidarRuntime =
|
|||||||
host: brainslugHost,
|
host: brainslugHost,
|
||||||
port: brainslugPort,
|
port: brainslugPort,
|
||||||
key: brainslugKey,
|
key: brainslugKey,
|
||||||
|
logFile: brainslugLogFile,
|
||||||
shouldPoll: () => Boolean(homeAssistantEnabled && isHomeAssistantConnected() && hasVerifiedSockets()),
|
shouldPoll: () => Boolean(homeAssistantEnabled && isHomeAssistantConnected() && hasVerifiedSockets()),
|
||||||
requestScan: requestLidarScan,
|
requestScan: requestLidarScan,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const SCAN_TIMEOUT_MS = 4000;
|
const SCAN_TIMEOUT_MS = 4000;
|
||||||
const RECONNECT_DELAY_MS = 5000;
|
const RECONNECT_DELAY_MS = 5000;
|
||||||
@@ -41,7 +42,7 @@ function parseRotationSpeed(payload) {
|
|||||||
return Number(match[1]);
|
return Number(match[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createLidarRuntime({ logger, host, port = 6053, key, shouldPoll, requestScan }) {
|
function createLidarRuntime({ logger, host, port = 6053, key, logFile = '', shouldPoll, requestScan }) {
|
||||||
const events = new EventEmitter();
|
const events = new EventEmitter();
|
||||||
const state = {
|
const state = {
|
||||||
connected: false,
|
connected: false,
|
||||||
@@ -53,6 +54,7 @@ function createLidarRuntime({ logger, host, port = 6053, key, shouldPoll, reques
|
|||||||
currentScan: null,
|
currentScan: null,
|
||||||
requestInFlight: false,
|
requestInFlight: false,
|
||||||
requestStartedAt: 0,
|
requestStartedAt: 0,
|
||||||
|
logStream: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
function emitStatus() {
|
function emitStatus() {
|
||||||
@@ -137,6 +139,9 @@ function createLidarRuntime({ logger, host, port = 6053, key, shouldPoll, reques
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleStdoutChunk(chunk) {
|
function handleStdoutChunk(chunk) {
|
||||||
|
if (state.logStream) {
|
||||||
|
state.logStream.write(String(chunk || ''));
|
||||||
|
}
|
||||||
state.stdoutBuffer += String(chunk || '');
|
state.stdoutBuffer += String(chunk || '');
|
||||||
const lines = state.stdoutBuffer.split(/\r?\n/);
|
const lines = state.stdoutBuffer.split(/\r?\n/);
|
||||||
state.stdoutBuffer = lines.pop() || '';
|
state.stdoutBuffer = lines.pop() || '';
|
||||||
@@ -163,9 +168,31 @@ function createLidarRuntime({ logger, host, port = 6053, key, shouldPoll, reques
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureLogStream() {
|
||||||
|
if (!logFile || state.logStream) return;
|
||||||
|
try {
|
||||||
|
state.logStream = fs.createWriteStream(logFile, { flags: 'a' });
|
||||||
|
logger.info('Neato lidar raw log capture enabled', { logFile });
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn('Failed to open Neato lidar raw log file', { logFile, error: err.message });
|
||||||
|
state.logStream = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeLogStream() {
|
||||||
|
if (!state.logStream) return;
|
||||||
|
try {
|
||||||
|
state.logStream.end();
|
||||||
|
} catch (err) {
|
||||||
|
logger.warn('Failed to close Neato lidar raw log file', err.message);
|
||||||
|
}
|
||||||
|
state.logStream = null;
|
||||||
|
}
|
||||||
|
|
||||||
function startLogStream() {
|
function startLogStream() {
|
||||||
if (!host || !key) return;
|
if (!host || !key) return;
|
||||||
if (state.process) return;
|
if (state.process) return;
|
||||||
|
ensureLogStream();
|
||||||
|
|
||||||
const args = [
|
const args = [
|
||||||
'--from',
|
'--from',
|
||||||
@@ -244,6 +271,7 @@ function createLidarRuntime({ logger, host, port = 6053, key, shouldPoll, reques
|
|||||||
clearPollSoonTimer();
|
clearPollSoonTimer();
|
||||||
clearRequestTimeoutTimer();
|
clearRequestTimeoutTimer();
|
||||||
teardownProcess();
|
teardownProcess();
|
||||||
|
closeLogStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getState() {
|
function getState() {
|
||||||
|
|||||||
Reference in New Issue
Block a user