mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
kjf
This commit is contained in:
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|||||||
|
|
||||||
const SCAN_TIMEOUT_MS = 8000;
|
const SCAN_TIMEOUT_MS = 8000;
|
||||||
const RECONNECT_DELAY_MS = 5000;
|
const RECONNECT_DELAY_MS = 5000;
|
||||||
|
const IDLE_RETRY_MS = 1000;
|
||||||
|
|
||||||
function sanitizeLogText(value) {
|
function sanitizeLogText(value) {
|
||||||
return String(value || '')
|
return String(value || '')
|
||||||
@@ -111,6 +112,14 @@ function createLidarRuntime({ logger, host, port = 6053, key, logFile = '', shou
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function schedulePollRetry(delayMs = IDLE_RETRY_MS) {
|
||||||
|
if (state.pollSoonTimer) return;
|
||||||
|
state.pollSoonTimer = setTimeout(() => {
|
||||||
|
state.pollSoonTimer = null;
|
||||||
|
tickPoll();
|
||||||
|
}, delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
function scheduleReconnect() {
|
function scheduleReconnect() {
|
||||||
if (state.reconnectTimer) return;
|
if (state.reconnectTimer) return;
|
||||||
state.reconnectTimer = setTimeout(() => {
|
state.reconnectTimer = setTimeout(() => {
|
||||||
@@ -330,8 +339,14 @@ function createLidarRuntime({ logger, host, port = 6053, key, logFile = '', shou
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function tickPoll() {
|
async function tickPoll() {
|
||||||
if (!state.connected) return;
|
if (!state.connected) {
|
||||||
if (!shouldPoll?.()) return;
|
schedulePollRetry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!shouldPoll?.()) {
|
||||||
|
schedulePollRetry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (state.requestInFlight) return;
|
if (state.requestInFlight) return;
|
||||||
state.requestInFlight = true;
|
state.requestInFlight = true;
|
||||||
state.requestStartedAt = Date.now();
|
state.requestStartedAt = Date.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user