mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-11-16 19:52:17 -05:00
roverstate yay yay. future implements for non-roomba rovers...
Container image / image (push) Failing after 54s
Container image / image (push) Failing after 54s
This commit is contained in:
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -18,7 +18,7 @@ Select the appropriate architecture binary on a rover. The default object suppli
|
|||||||
|
|
||||||
## Connections and state
|
## Connections and state
|
||||||
|
|
||||||
- `/rover`: existing control commands, acknowledgements, sensors, and operational toggle state. The planned full `roverState` replacement is not implemented yet.
|
- `/rover`: control commands, acknowledgements, sensors, and complete `roverState` snapshots.
|
||||||
- `/rover/management`: configuration hello, management commands/acknowledgements, host statistics, and daemon events.
|
- `/rover/management`: configuration hello, management commands/acknowledgements, host statistics, and daemon events.
|
||||||
- Derive the management address from the configured `ws://host[:port]/rover` or `wss://host[:port]/rover` control URL; there is no second server address to maintain.
|
- Derive the management address from the configured `ws://host[:port]/rover` or `wss://host[:port]/rover` control URL; there is no second server address to maintain.
|
||||||
- Management starts independently of hardware initialization and remains available after serial/peripheral startup failure.
|
- Management starts independently of hardware initialization and remains available after serial/peripheral startup failure.
|
||||||
@@ -64,7 +64,7 @@ Do this on the intended server/rover, not the development machine:
|
|||||||
2. With an authenticated admin Socket.IO session, call `roverManagement:list` and `roverManagement:get`. Expect configuration and schema even when the rover's serial device cannot open.
|
2. With an authenticated admin Socket.IO session, call `roverManagement:list` and `roverManagement:get`. Expect configuration and schema even when the rover's serial device cannot open.
|
||||||
3. Change a harmless setting such as description in the returned full object and call `roverManagement:save`. Expect an acknowledgement, disconnect/reconnect, and a new hello containing that setting. Confirm `/etc/roverd.json` matches and survives a service restart.
|
3. Change a harmless setting such as description in the returned full object and call `roverManagement:save`. Expect an acknowledgement, disconnect/reconnect, and a new hello containing that setting. Confirm `/etc/roverd.json` matches and survives a service restart.
|
||||||
4. Submit an incomplete object. Expect an error, no file replacement, and no restart.
|
4. Submit an incomplete object. Expect an error, no file replacement, and no restart.
|
||||||
5. Confirm host statistics and autocharge/watchdog/daemon notices still reach their existing UI/alert consumers through management. Headlight/laser state must remain on control.
|
5. Confirm host statistics and autocharge/watchdog/daemon notices still reach their existing UI/alert consumers through management. Headlight/laser state must arrive as a complete `roverState` snapshot on control.
|
||||||
6. Verify reboot/update requests use management, the normal user reboot restrictions still apply, and non-admin clients cannot read/save configuration or invoke the admin command endpoint.
|
6. Verify reboot/update requests use management, the normal user reboot restrictions still apply, and non-admin clients cannot read/save configuration or invoke the admin command endpoint.
|
||||||
7. Confirm new movement commands cannot execute while a save/reboot/update is stopping the rover, and that control disconnect safety still works independently of management.
|
7. Confirm new movement commands cannot execute while a save/reboot/update is stopping the rover, and that control disconnect safety still works independently of management.
|
||||||
|
|
||||||
@@ -72,6 +72,8 @@ Record acknowledgement errors, reconnect hello contents, relevant journal/server
|
|||||||
|
|
||||||
## Pending stages
|
## Pending stages
|
||||||
|
|
||||||
Browser/live verification of the configuration page, shared `roverState`, YAML media catalogs/child supervision, universal ALSA routing, standalone bootstrap, and replacement update workflow remain pending. The current updater and systemd media supervisor have moved transport but retain their existing implementations until those stages.
|
Browser/live verification of configuration and operational state, YAML media catalogs/child supervision, universal ALSA routing, standalone bootstrap, and replacement update workflow remain pending. The current updater and systemd media supervisor have moved transport but retain their existing implementations until those stages.
|
||||||
|
|
||||||
Apply-field targets the currently management-connected fleet. It clones each rover’s own configuration, replaces an existing field, and sends the complete object for rover-side validation. Inspect individual results for failures. Missing fields and changed connections are reported; offline changes are not queued. Paths traverse object fields, not array elements. Array-valued fields can be replaced as a whole.
|
Apply-field targets the currently management-connected fleet. It clones each rover’s own configuration, replaces an existing field, and sends the complete object for rover-side validation. Inspect individual results for failures. Missing fields and changed connections are reported; offline changes are not queued. Paths traverse object fields, not array elements. Array-valued fields can be replaced as a whole.
|
||||||
|
|
||||||
|
Control state messages have the shape `{ "type": "roverState", "state": { "headlightOn": false, "laserOn": null } }`. Null indicates an unavailable role. Each message replaces the server object; disconnect clears it. The roster exposes `roverState` directly, rather than per-device `state` objects.
|
||||||
|
|||||||
@@ -159,15 +159,15 @@ The order below is a working sequence, not a requirement to leave incompatible i
|
|||||||
- [x] Rename `pi/` to `rover/` and update references.
|
- [x] Rename `pi/` to `rover/` and update references.
|
||||||
- [x] Replace machine-specific build targets/tags with architecture-specific artifacts and resolve hardware support split.
|
- [x] Replace machine-specific build targets/tags with architecture-specific artifacts and resolve hardware support split.
|
||||||
- [x] Group every native GPIO setting under the disabled-by-default Pi GPIO peripheral switch in the current configuration and samples.
|
- [x] Group every native GPIO setting under the disabled-by-default Pi GPIO peripheral switch in the current configuration and samples.
|
||||||
- [ ] Expose the grouped Pi GPIO configuration in the new JSON schema/UI.
|
- [x] Expose the grouped Pi GPIO configuration in the new JSON schema/UI.
|
||||||
- [x] Register Pi GPIO through the common peripheral provider path, including BRC lifecycle ownership and uniform role-conflict handling.
|
- [x] Register Pi GPIO through the common peripheral provider path, including BRC lifecycle ownership and uniform role-conflict handling.
|
||||||
- [ ] Connect peripheral operational state to the new shared `roverState` object.
|
- [x] Connect peripheral operational state to the new shared `roverState` object.
|
||||||
- [x] Gate GPIO provider registration, initialization, and BRC startup behind the parent switch; retain saved child settings. Hardware validation remains pending.
|
- [x] Gate GPIO provider registration, initialization, and BRC startup behind the parent switch; retain saved child settings. Hardware validation remains pending.
|
||||||
- [x] Implement complete JSON configuration serialization, schema, validation, atomic saves, and restart flow (live save/reconnect verification pending).
|
- [x] Implement complete JSON configuration serialization, schema, validation, atomic saves, and restart flow (live save/reconnect verification pending).
|
||||||
- [x] Implement separate management connection and in-memory server management state.
|
- [x] Implement separate management connection and in-memory server management state.
|
||||||
- [x] Move reboot, update, media management, host statistics, and daemon status messages to management; update consumers. Preserve the separately authorized user reboot path.
|
- [x] Move reboot, update, media management, host statistics, and daemon status messages to management; update consumers. Preserve the separately authorized user reboot path.
|
||||||
- [x] Separate management lifecycle from hardware startup failures (deployment verification pending).
|
- [x] Separate management lifecycle from hardware startup failures (deployment verification pending).
|
||||||
- [ ] Implement full-object `roverState` and consolidate server/UI operational-state consumers.
|
- [x] Implement full-object `roverState` and consolidate server/UI operational-state consumers (live verification pending).
|
||||||
- [ ] Add bundled YAML catalogs and one custom YAML profile per media category.
|
- [ ] Add bundled YAML catalogs and one custom YAML profile per media category.
|
||||||
- [ ] Preserve AIY HAT as an explicit profile and expose ordinary audio-device selection on every architecture, including TTS/horn/mixer paths.
|
- [ ] Preserve AIY HAT as an explicit profile and expose ordinary audio-device selection on every architecture, including TTS/horn/mixer paths.
|
||||||
- [ ] Generate ALSA routing from shared input/output selections; connect microphone, TTS, horn, forwarded audio, and independent volume controls to the resulting logical devices.
|
- [ ] Generate ALSA routing from shared input/output selections; connect microphone, TTS, horn, forwarded audio, and independent volume controls to the resulting logical devices.
|
||||||
@@ -264,3 +264,12 @@ Verification for this stage:
|
|||||||
- Configuration UI/backend implementation is now present; end-to-end deployment verification remains pending. Profile/status/output controls, unified rover state, audio/media supervision, and bootstrap/update rework are still separate outstanding stages.
|
- Configuration UI/backend implementation is now present; end-to-end deployment verification remains pending. Profile/status/output controls, unified rover state, audio/media supervision, and bootstrap/update rework are still separate outstanding stages.
|
||||||
|
|
||||||
- Placement correction: rover configuration is embedded in the existing fleet management panel alongside the rover roster. Removed the separate administration tab.
|
- Placement correction: rover configuration is embedded in the existing fleet management panel alongside the rover roster. Removed the separate administration tab.
|
||||||
|
|
||||||
|
### Unified operational state (2026-11-16)
|
||||||
|
|
||||||
|
- Roverd owns a complete `roverState` object with `headlightOn` and `laserOn`; null indicates an unavailable role. Sends on control connection/reconnection and logical changes. Pending notifications coalesce to the latest complete snapshot.
|
||||||
|
- Server replaces one current object, exposes it in roster snapshots, and clears it on disconnect. Superseded sockets cannot overwrite state or remove a newer connection. Removed per-toggle event handling and separate server state stores.
|
||||||
|
- Desktop/mobile/HUD controls, darkness reward restoration, and learning snapshots read the shared object. Telemetry and daemon management remain separate.
|
||||||
|
- All four architecture binaries rebuilt successfully; focused frontend lint and server syntax checks passed. The two existing roster lifecycle tests passed after updating their state fixture. No new tests added.
|
||||||
|
- Still verify live initial state, toggles through both GPIO/Firmata, reconnect state, disconnect clearing, and darkness restoration. Production UI assets have not been rebuilt.
|
||||||
|
- Next implementation stage: YAML media profiles, command environments and child-process supervision, alongside the planned universal audio routing.
|
||||||
|
|||||||
+94
-66
@@ -15,39 +15,41 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type WSClient struct {
|
type WSClient struct {
|
||||||
autoCharge *AutoChargeController
|
autoCharge *AutoChargeController
|
||||||
commandMu sync.Mutex
|
commandMu sync.Mutex
|
||||||
stopping atomic.Bool
|
stopping atomic.Bool
|
||||||
controlEvents chan RoverEvent
|
stateChanged chan struct{}
|
||||||
cfg *Config
|
stateMu sync.Mutex
|
||||||
adapter *SerialAdapter
|
roverState RoverState
|
||||||
sensorFrames <-chan []byte
|
cfg *Config
|
||||||
events chan RoverEvent
|
adapter *SerialAdapter
|
||||||
media *MediaSupervisor
|
sensorFrames <-chan []byte
|
||||||
servo CameraServoController
|
events chan RoverEvent
|
||||||
horn *HornSynth
|
media *MediaSupervisor
|
||||||
headlight ToggleController
|
servo CameraServoController
|
||||||
laser ToggleController
|
horn *HornSynth
|
||||||
peripherals *PeripheralManager
|
headlight ToggleController
|
||||||
log *log.Logger
|
laser ToggleController
|
||||||
console *ConsoleNotifier
|
peripherals *PeripheralManager
|
||||||
recoverMu sync.Mutex
|
log *log.Logger
|
||||||
recovering bool
|
console *ConsoleNotifier
|
||||||
watchdogMu sync.Mutex
|
recoverMu sync.Mutex
|
||||||
watchdogOpen bool
|
recovering bool
|
||||||
watchdogOK bool
|
watchdogMu sync.Mutex
|
||||||
ttsQueue chan *ttsPayload
|
watchdogOpen bool
|
||||||
chromeTTS *chromeTTSDaemon
|
watchdogOK bool
|
||||||
lastAux motorPWMPayload
|
ttsQueue chan *ttsPayload
|
||||||
autoSideOn bool
|
chromeTTS *chromeTTSDaemon
|
||||||
connMu sync.Mutex
|
lastAux motorPWMPayload
|
||||||
connected bool
|
autoSideOn bool
|
||||||
disconnectT *time.Timer
|
connMu sync.Mutex
|
||||||
rebootT *time.Timer
|
connected bool
|
||||||
seekIssued bool
|
disconnectT *time.Timer
|
||||||
rebootIssued bool
|
rebootT *time.Timer
|
||||||
audioLevels AudioLevels
|
seekIssued bool
|
||||||
audioMu sync.RWMutex
|
rebootIssued bool
|
||||||
|
audioLevels AudioLevels
|
||||||
|
audioMu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWSClient(cfg *Config, adapter *SerialAdapter, frames <-chan []byte, events chan RoverEvent, media *MediaSupervisor, servo CameraServoController, headlight ToggleController, laser ToggleController, peripherals *PeripheralManager, logger *log.Logger, console *ConsoleNotifier) *WSClient {
|
func NewWSClient(cfg *Config, adapter *SerialAdapter, frames <-chan []byte, events chan RoverEvent, media *MediaSupervisor, servo CameraServoController, headlight ToggleController, laser ToggleController, peripherals *PeripheralManager, logger *log.Logger, console *ConsoleNotifier) *WSClient {
|
||||||
@@ -64,21 +66,21 @@ func NewWSClient(cfg *Config, adapter *SerialAdapter, frames <-chan []byte, even
|
|||||||
horn = NewHornSynth(cfg.Horn, logger)
|
horn = NewHornSynth(cfg.Horn, logger)
|
||||||
}
|
}
|
||||||
client := &WSClient{
|
client := &WSClient{
|
||||||
controlEvents: make(chan RoverEvent, 16),
|
stateChanged: make(chan struct{}, 1),
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
adapter: adapter,
|
adapter: adapter,
|
||||||
sensorFrames: frames,
|
sensorFrames: frames,
|
||||||
events: events,
|
events: events,
|
||||||
media: media,
|
media: media,
|
||||||
servo: servo,
|
servo: servo,
|
||||||
horn: horn,
|
horn: horn,
|
||||||
headlight: headlight,
|
headlight: headlight,
|
||||||
laser: laser,
|
laser: laser,
|
||||||
peripherals: peripherals,
|
peripherals: peripherals,
|
||||||
log: logger,
|
log: logger,
|
||||||
console: console,
|
console: console,
|
||||||
ttsQueue: ttsQueue,
|
ttsQueue: ttsQueue,
|
||||||
chromeTTS: chromeTTS,
|
chromeTTS: chromeTTS,
|
||||||
audioLevels: AudioLevels{
|
audioLevels: AudioLevels{
|
||||||
HornGain: 1.0,
|
HornGain: 1.0,
|
||||||
TTSGain: 1.0,
|
TTSGain: 1.0,
|
||||||
@@ -109,6 +111,7 @@ func (c *WSClient) Run(ctx context.Context) error {
|
|||||||
defer c.chromeTTS.Shutdown()
|
defer c.chromeTTS.Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.refreshState()
|
||||||
if err := c.sendHello(ctx, conn); err != nil {
|
if err := c.sendHello(ctx, conn); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -128,7 +131,7 @@ func (c *WSClient) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go c.forwardSensors(ctx, conn)
|
go c.forwardSensors(ctx, conn)
|
||||||
go c.forwardEvents(ctx, conn)
|
go c.forwardState(ctx, conn)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -284,12 +287,7 @@ func (c *WSClient) handleToggleCommand(name string, toggle ToggleController, pay
|
|||||||
if err := toggle.HandleAction(payload.Action); err != nil {
|
if err := toggle.HandleAction(payload.Action); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Event names and payload keys use logical device names. GPIO polarity has
|
c.refreshState()
|
||||||
// already been handled inside GPIOToggle, so the server only sees whether
|
|
||||||
// the headlight or laser should be considered on.
|
|
||||||
c.emitEvent(fmt.Sprintf("%s.state", name), map[string]any{
|
|
||||||
fmt.Sprintf("%sOn", name): toggle.On(),
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,20 +470,53 @@ func (c *WSClient) forwardSensors(ctx context.Context, conn *websocket.Conn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSClient) forwardEvents(ctx context.Context, conn *websocket.Conn) {
|
// RoverState is a complete operational snapshot; nil means the role is absent.
|
||||||
if c.events == nil {
|
type RoverState struct {
|
||||||
|
HeadlightOn *bool `json:"headlightOn"`
|
||||||
|
LaserOn *bool `json:"laserOn"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WSClient) refreshState() {
|
||||||
|
next := RoverState{}
|
||||||
|
if c.headlight != nil {
|
||||||
|
value := c.headlight.On()
|
||||||
|
next.HeadlightOn = &value
|
||||||
|
}
|
||||||
|
if c.laser != nil {
|
||||||
|
value := c.laser.On()
|
||||||
|
next.LaserOn = &value
|
||||||
|
}
|
||||||
|
c.stateMu.Lock()
|
||||||
|
old, _ := json.Marshal(c.roverState)
|
||||||
|
updated, _ := json.Marshal(next)
|
||||||
|
c.roverState = next
|
||||||
|
c.stateMu.Unlock()
|
||||||
|
if string(old) != string(updated) {
|
||||||
|
select {
|
||||||
|
case c.stateChanged <- struct{}{}:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WSClient) forwardState(ctx context.Context, conn *websocket.Conn) {
|
||||||
|
send := func() error {
|
||||||
|
c.stateMu.Lock()
|
||||||
|
state := c.roverState
|
||||||
|
c.stateMu.Unlock()
|
||||||
|
return writeJSON(ctx, conn, map[string]any{"type": "roverState", "state": state})
|
||||||
|
}
|
||||||
|
if err := send(); err != nil {
|
||||||
|
conn.CloseNow()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case evt := <-c.controlEvents:
|
case <-c.stateChanged:
|
||||||
if evt.Type == "" {
|
if err := send(); err != nil {
|
||||||
evt.Type = "event"
|
conn.CloseNow()
|
||||||
}
|
|
||||||
if err := writeJSON(ctx, conn, evt); err != nil {
|
|
||||||
c.log.Printf("event send failed: %v", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -494,9 +525,6 @@ func (c *WSClient) forwardEvents(ctx context.Context, conn *websocket.Conn) {
|
|||||||
|
|
||||||
func (c *WSClient) emitEvent(event string, data map[string]any) {
|
func (c *WSClient) emitEvent(event string, data map[string]any) {
|
||||||
events := c.events
|
events := c.events
|
||||||
if event == "headlight.state" || event == "laser.state" {
|
|
||||||
events = c.controlEvents
|
|
||||||
}
|
|
||||||
if events == nil {
|
if events == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ module.exports = {
|
|||||||
|
|
||||||
const prevHeadlights = {};
|
const prevHeadlights = {};
|
||||||
ctx.listOnlineRovers().forEach((rover) => {
|
ctx.listOnlineRovers().forEach((rover) => {
|
||||||
const state = rover?.headlight?.state;
|
const state = rover?.roverState;
|
||||||
const headlightOn = Boolean(state && state.headlightOn === true);
|
const headlightOn = Boolean(state && state.headlightOn === true);
|
||||||
prevHeadlights[String(rover.id)] = headlightOn;
|
prevHeadlights[String(rover.id)] = headlightOn;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -8,39 +8,8 @@ const { sendAlert } = require('../alertService');
|
|||||||
const ALERT_COLOR = '#00bcd4';
|
const ALERT_COLOR = '#00bcd4';
|
||||||
const { handleAck } = require('../commandService');
|
const { handleAck } = require('../commandService');
|
||||||
|
|
||||||
function coerceBool(value) {
|
|
||||||
if (typeof value === 'boolean') return value;
|
|
||||||
if (typeof value === 'number') return value !== 0;
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
const normalized = value.trim().toLowerCase();
|
|
||||||
if (normalized === 'true') return true;
|
|
||||||
if (normalized === 'false') return false;
|
|
||||||
if (normalized === '1') return true;
|
|
||||||
if (normalized === '0') return false;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HEARTBEAT_INTERVAL_MS = 15000;
|
const HEARTBEAT_INTERVAL_MS = 15000;
|
||||||
|
|
||||||
function handleToggleEvent(roverId, msg) {
|
|
||||||
if (msg.event === 'headlight.state') {
|
|
||||||
const headlightOn = coerceBool(msg.data?.headlightOn);
|
|
||||||
if (headlightOn != null) {
|
|
||||||
roverManager.setToggleState(roverId, 'headlight', headlightOn);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (msg.event === 'laser.state') {
|
|
||||||
const laserOn = coerceBool(msg.data?.laserOn);
|
|
||||||
if (laserOn != null) {
|
|
||||||
roverManager.setToggleState(roverId, 'laser', laserOn);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
roverWSS.on('connection', (ws) => {
|
roverWSS.on('connection', (ws) => {
|
||||||
let roverId = null;
|
let roverId = null;
|
||||||
ws.isAlive = true;
|
ws.isAlive = true;
|
||||||
@@ -80,19 +49,19 @@ roverWSS.on('connection', (ws) => {
|
|||||||
sendAlert({ color: ALERT_COLOR, title: 'Rover Online', message: roverId });
|
sendAlert({ color: ALERT_COLOR, title: 'Rover Online', message: roverId });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!roverId) return;
|
if (!roverId || roverManager.rovers.get(roverId)?.ws !== ws) return;
|
||||||
if (msg.type === 'sensor') {
|
if (msg.type === 'sensor') {
|
||||||
roverManager.handleSensorFrame(roverId, msg);
|
roverManager.handleSensorFrame(roverId, msg);
|
||||||
} else if (msg.type === 'ack') {
|
} else if (msg.type === 'ack') {
|
||||||
handleAck(msg);
|
handleAck(msg);
|
||||||
} else if (msg.type === 'event') {
|
} else if (msg.type === 'roverState') {
|
||||||
handleToggleEvent(roverId, msg);
|
roverManager.setRoverState(roverId, msg.state);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
clearInterval(heartbeat);
|
clearInterval(heartbeat);
|
||||||
if (roverId) {
|
if (roverId && roverManager.rovers.get(roverId)?.ws === ws) {
|
||||||
roverManager.removeRover(roverId);
|
roverManager.removeRover(roverId);
|
||||||
sendAlert({ color: ALERT_COLOR, title: 'Rover Offline', message: roverId });
|
sendAlert({ color: ALERT_COLOR, title: 'Rover Offline', message: roverId });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,8 +116,7 @@ function createRuntime({ config, logger }) {
|
|||||||
// Do not serialize the live record: it contains sockets and circular state.
|
// Do not serialize the live record: it contains sockets and circular state.
|
||||||
return {
|
return {
|
||||||
meta: record.meta, sensors: record.lastSensor, hostStats: record.lastHostStats,
|
meta: record.meta, sensors: record.lastSensor, hostStats: record.lastHostStats,
|
||||||
batteryState: record.batteryState, headlightState: record.headlightState,
|
batteryState: record.batteryState, roverState: record.roverState, drivers: [...(record.drivers || [])],
|
||||||
laserState: record.laserState, drivers: [...(record.drivers || [])],
|
|
||||||
locked: record.locked, privateOpen: record.privateOpen,
|
locked: record.locked, privateOpen: record.privateOpen,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ const {
|
|||||||
getRosterForSocket,
|
getRosterForSocket,
|
||||||
broadcastRoster,
|
broadcastRoster,
|
||||||
setNeedsHelp,
|
setNeedsHelp,
|
||||||
setToggleState,
|
setRoverState,
|
||||||
handleHostStats,
|
handleHostStats,
|
||||||
canSeeRover,
|
canSeeRover,
|
||||||
canRequestControl,
|
canRequestControl,
|
||||||
@@ -284,7 +284,7 @@ module.exports = {
|
|||||||
getRosterForSocket,
|
getRosterForSocket,
|
||||||
broadcastRoster,
|
broadcastRoster,
|
||||||
setNeedsHelp,
|
setNeedsHelp,
|
||||||
setToggleState,
|
setRoverState,
|
||||||
handleHostStats,
|
handleHostStats,
|
||||||
handleSensorFrame,
|
handleSensorFrame,
|
||||||
requestControl,
|
requestControl,
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ function createRosterLifecycle(deps) {
|
|||||||
locked: false,
|
locked: false,
|
||||||
lockReason: null,
|
lockReason: null,
|
||||||
batteryState: null,
|
batteryState: null,
|
||||||
headlightState: null,
|
roverState: null,
|
||||||
laserState: null,
|
|
||||||
room: `rover:${id}`,
|
room: `rover:${id}`,
|
||||||
lastSeen: Date.now(),
|
lastSeen: Date.now(),
|
||||||
lastMovementAt: Date.now(),
|
lastMovementAt: Date.now(),
|
||||||
@@ -79,22 +78,7 @@ function createRosterLifecycle(deps) {
|
|||||||
} else {
|
} else {
|
||||||
record.privateOpen = true;
|
record.privateOpen = true;
|
||||||
}
|
}
|
||||||
if (!meta?.headlight?.enabled) {
|
record.roverState = null;
|
||||||
record.headlightState = null;
|
|
||||||
} else if (record.headlightState == null) {
|
|
||||||
record.headlightState = {
|
|
||||||
headlightOn: Boolean(meta.headlight.initialOn),
|
|
||||||
updatedAt: Date.now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (!meta?.laser?.enabled) {
|
|
||||||
record.laserState = null;
|
|
||||||
} else if (record.laserState == null) {
|
|
||||||
record.laserState = {
|
|
||||||
laserOn: Boolean(meta.laser.initialOn),
|
|
||||||
updatedAt: Date.now(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
rovers.set(id, record);
|
rovers.set(id, record);
|
||||||
spectatorSockets.forEach((socketId) => {
|
spectatorSockets.forEach((socketId) => {
|
||||||
const sock = io.sockets.sockets.get(socketId);
|
const sock = io.sockets.sockets.get(socketId);
|
||||||
@@ -118,6 +102,7 @@ function createRosterLifecycle(deps) {
|
|||||||
it can clean the reverse membership index and Socket.IO room membership.
|
it can clean the reverse membership index and Socket.IO room membership.
|
||||||
*/
|
*/
|
||||||
require('../dockingService').disconnect(record);
|
require('../dockingService').disconnect(record);
|
||||||
|
record.roverState = null;
|
||||||
rovers.delete(id);
|
rovers.delete(id);
|
||||||
removeRoverDrivers(id, record);
|
removeRoverDrivers(id, record);
|
||||||
stopDockGuard(id);
|
stopDockGuard(id);
|
||||||
@@ -249,12 +234,9 @@ function createRosterLifecycle(deps) {
|
|||||||
// controls. Preserve that order here instead of rebuilding the inventory,
|
// controls. Preserve that order here instead of rebuilding the inventory,
|
||||||
// because ESP32 registration order is also the driver's display order.
|
// because ESP32 registration order is also the driver's display order.
|
||||||
peripherals: Array.isArray(record.meta?.peripherals) ? record.meta.peripherals : [],
|
peripherals: Array.isArray(record.meta?.peripherals) ? record.meta.peripherals : [],
|
||||||
headlight: record.meta?.headlight
|
headlight: record.meta?.headlight,
|
||||||
? { ...record.meta.headlight, state: record.headlightState }
|
laser: record.meta?.laser,
|
||||||
: record.meta?.headlight,
|
roverState: record.roverState,
|
||||||
laser: record.meta?.laser
|
|
||||||
? { ...record.meta.laser, state: record.laserState }
|
|
||||||
: record.meta?.laser,
|
|
||||||
locked: record.locked || (isPrivateRecord(record) && !isPrivateOpen(record)),
|
locked: record.locked || (isPrivateRecord(record) && !isPrivateOpen(record)),
|
||||||
lockReason: record.lockReason || (isPrivateRecord(record) && !isPrivateOpen(record) ? 'private' : null),
|
lockReason: record.lockReason || (isPrivateRecord(record) && !isPrivateOpen(record) ? 'private' : null),
|
||||||
needsHelp: Boolean(record.needsHelp),
|
needsHelp: Boolean(record.needsHelp),
|
||||||
@@ -290,19 +272,14 @@ function createRosterLifecycle(deps) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setToggleState(roverId, device, on) {
|
function setRoverState(roverId, state) {
|
||||||
const record = rovers.get(roverId);
|
const record = rovers.get(roverId);
|
||||||
if (!record) return;
|
if (!record || !state || typeof state !== 'object' || Array.isArray(state)) return;
|
||||||
if (typeof on !== 'boolean') return;
|
if (!['headlightOn', 'laserOn'].every((key) => Object.hasOwn(state, key)
|
||||||
if (device !== 'headlight' && device !== 'laser') return;
|
&& (state[key] === null || typeof state[key] === 'boolean'))) return;
|
||||||
const stateKey = device === 'headlight' ? 'headlightState' : 'laserState';
|
record.roverState = state;
|
||||||
const onKey = `${device}On`;
|
|
||||||
record[stateKey] = {
|
|
||||||
[onKey]: on,
|
|
||||||
updatedAt: Date.now(),
|
|
||||||
};
|
|
||||||
broadcastRoster();
|
broadcastRoster();
|
||||||
managerEvents.emit('rover', { roverId, action: device, record });
|
managerEvents.emit('rover', { roverId, action: 'roverState', record });
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNeedsHelp(roverId, needsHelp) {
|
function setNeedsHelp(roverId, needsHelp) {
|
||||||
@@ -367,7 +344,7 @@ function createRosterLifecycle(deps) {
|
|||||||
syncSpectatorRooms,
|
syncSpectatorRooms,
|
||||||
broadcastRoster,
|
broadcastRoster,
|
||||||
setNeedsHelp,
|
setNeedsHelp,
|
||||||
setToggleState,
|
setRoverState,
|
||||||
handleHostStats,
|
handleHostStats,
|
||||||
canSeeRover,
|
canSeeRover,
|
||||||
canRequestControl,
|
canRequestControl,
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ function createRosterManager(meta) {
|
|||||||
id: meta.name,
|
id: meta.name,
|
||||||
meta,
|
meta,
|
||||||
batteryState: null,
|
batteryState: null,
|
||||||
headlightState: null,
|
roverState: null,
|
||||||
laserState: null,
|
|
||||||
locked: false,
|
locked: false,
|
||||||
lockReason: null,
|
lockReason: null,
|
||||||
lastSeen: 123,
|
lastSeen: 123,
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export default function BottomLeftPod({ roverId }) {
|
|||||||
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
||||||
const laser = useControlSelector((control) => control.pipeline?.laser);
|
const laser = useControlSelector((control) => control.pipeline?.laser);
|
||||||
const hornDevice = useControlSelector((control) => control.pipeline?.horn);
|
const hornDevice = useControlSelector((control) => control.pipeline?.horn);
|
||||||
const headlightOn = useControlSelector((control) => Boolean(control.pipeline?.headlightState?.headlightOn));
|
const headlightOn = useControlSelector((control) => Boolean(control.pipeline?.roverState?.headlightOn));
|
||||||
const laserOn = useControlSelector((control) => Boolean(control.pipeline?.laserState?.laserOn));
|
const laserOn = useControlSelector((control) => Boolean(control.pipeline?.roverState?.laserOn));
|
||||||
const hornActive = useControlSelector((control) => Boolean(control.state.horn?.active));
|
const hornActive = useControlSelector((control) => Boolean(control.state.horn?.active));
|
||||||
const { setHeadlight, setLaser, startHorn, stopHorn } = useControlActions();
|
const { setHeadlight, setLaser, startHorn, stopHorn } = useControlActions();
|
||||||
const canControl = useCanControlRover(roverId);
|
const canControl = useCanControlRover(roverId);
|
||||||
|
|||||||
@@ -27,9 +27,8 @@ function AuxColumnContent({ accessoriesAvailable, onShowAccessories }) {
|
|||||||
const camera = useControlSelector((control) => control.state.camera);
|
const camera = useControlSelector((control) => control.state.camera);
|
||||||
const horn = useControlSelector((control) => control.state.horn);
|
const horn = useControlSelector((control) => control.state.horn);
|
||||||
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
||||||
const headlightState = useControlSelector((control) => control.pipeline?.headlightState);
|
const roverState = useControlSelector((control) => control.pipeline?.roverState);
|
||||||
const laser = useControlSelector((control) => control.pipeline?.laser);
|
const laser = useControlSelector((control) => control.pipeline?.laser);
|
||||||
const laserState = useControlSelector((control) => control.pipeline?.laserState);
|
|
||||||
const pipelineHorn = useControlSelector((control) => control.pipeline?.horn);
|
const pipelineHorn = useControlSelector((control) => control.pipeline?.horn);
|
||||||
const { setServoAngle, setHeadlight, setLaser, setAuxMotors, startHorn, stopHorn } = useControlActions();
|
const { setServoAngle, setHeadlight, setLaser, setAuxMotors, startHorn, stopHorn } = useControlActions();
|
||||||
const dockTelemetry = useTelemetrySelector(roverId, selectDockTelemetry, dockTelemetryEqual);
|
const dockTelemetry = useTelemetrySelector(roverId, selectDockTelemetry, dockTelemetryEqual);
|
||||||
@@ -152,7 +151,7 @@ function AuxColumnContent({ accessoriesAvailable, onShowAccessories }) {
|
|||||||
<GPIOToggleControl
|
<GPIOToggleControl
|
||||||
label="Headlight"
|
label="Headlight"
|
||||||
icon={FaLightbulb}
|
icon={FaLightbulb}
|
||||||
on={headlightState?.headlightOn}
|
on={roverState?.headlightOn}
|
||||||
disabled={controlsDisabled}
|
disabled={controlsDisabled}
|
||||||
onToggle={handleHeadlightToggle}
|
onToggle={handleHeadlightToggle}
|
||||||
heightClass="h-full"
|
heightClass="h-full"
|
||||||
@@ -162,7 +161,7 @@ function AuxColumnContent({ accessoriesAvailable, onShowAccessories }) {
|
|||||||
<GPIOToggleControl
|
<GPIOToggleControl
|
||||||
label="Laser"
|
label="Laser"
|
||||||
icon={FaCrosshairs}
|
icon={FaCrosshairs}
|
||||||
on={laserState?.laserOn}
|
on={roverState?.laserOn}
|
||||||
disabled={controlsDisabled || roomLightsLockedOn}
|
disabled={controlsDisabled || roomLightsLockedOn}
|
||||||
onToggle={handleLaserToggle}
|
onToggle={handleLaserToggle}
|
||||||
heightClass="h-full"
|
heightClass="h-full"
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ export function useCommandPipeline(options = {}) {
|
|||||||
[rosterEntry],
|
[rosterEntry],
|
||||||
);
|
);
|
||||||
|
|
||||||
const headlightState = useMemo(() => rosterEntry?.headlight?.state ?? null, [rosterEntry]);
|
const roverState = rosterEntry?.roverState ?? null;
|
||||||
const laserState = useMemo(() => rosterEntry?.laser?.state ?? null, [rosterEntry]);
|
|
||||||
const emitCommand = useCallback(
|
const emitCommand = useCallback(
|
||||||
(payload, cb) => {
|
(payload, cb) => {
|
||||||
if (!roverId || !socket.connected) {
|
if (!roverId || !socket.connected) {
|
||||||
@@ -234,9 +233,8 @@ export function useCommandPipeline(options = {}) {
|
|||||||
rosterEntry,
|
rosterEntry,
|
||||||
servoConfig,
|
servoConfig,
|
||||||
headlight,
|
headlight,
|
||||||
headlightState,
|
roverState,
|
||||||
laser,
|
laser,
|
||||||
laserState,
|
|
||||||
horn,
|
horn,
|
||||||
peripherals,
|
peripherals,
|
||||||
emitCommand,
|
emitCommand,
|
||||||
@@ -256,9 +254,8 @@ export function useCommandPipeline(options = {}) {
|
|||||||
rosterEntry,
|
rosterEntry,
|
||||||
servoConfig,
|
servoConfig,
|
||||||
headlight,
|
headlight,
|
||||||
headlightState,
|
roverState,
|
||||||
laser,
|
laser,
|
||||||
laserState,
|
|
||||||
horn,
|
horn,
|
||||||
peripherals,
|
peripherals,
|
||||||
emitCommand,
|
emitCommand,
|
||||||
|
|||||||
@@ -58,9 +58,8 @@ function DriveDockPanel() {
|
|||||||
const camera = useControlSelector((control) => control.state.camera);
|
const camera = useControlSelector((control) => control.state.camera);
|
||||||
const horn = useControlSelector((control) => control.state.horn);
|
const horn = useControlSelector((control) => control.state.horn);
|
||||||
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
const headlight = useControlSelector((control) => control.pipeline?.headlight);
|
||||||
const headlightState = useControlSelector((control) => control.pipeline?.headlightState);
|
const roverState = useControlSelector((control) => control.pipeline?.roverState);
|
||||||
const laser = useControlSelector((control) => control.pipeline?.laser);
|
const laser = useControlSelector((control) => control.pipeline?.laser);
|
||||||
const laserState = useControlSelector((control) => control.pipeline?.laserState);
|
|
||||||
const pipelineHorn = useControlSelector((control) => control.pipeline?.horn);
|
const pipelineHorn = useControlSelector((control) => control.pipeline?.horn);
|
||||||
const { setServoAngle, setHeadlight, setLaser, startHorn, stopHorn } = useControlActions();
|
const { setServoAngle, setHeadlight, setLaser, startHorn, stopHorn } = useControlActions();
|
||||||
const dockTelemetry = useTelemetrySelector(roverId, selectDockTelemetry, dockTelemetryEqual);
|
const dockTelemetry = useTelemetrySelector(roverId, selectDockTelemetry, dockTelemetryEqual);
|
||||||
@@ -126,7 +125,7 @@ function DriveDockPanel() {
|
|||||||
{headlightAvailable && (
|
{headlightAvailable && (
|
||||||
<GPIOToggleControl
|
<GPIOToggleControl
|
||||||
label="Headlight"
|
label="Headlight"
|
||||||
on={headlightState?.headlightOn}
|
on={roverState?.headlightOn}
|
||||||
disabled={!roverId}
|
disabled={!roverId}
|
||||||
onToggle={auxControls.setHeadlight}
|
onToggle={auxControls.setHeadlight}
|
||||||
keyLabel={headlightLabel}
|
keyLabel={headlightLabel}
|
||||||
@@ -135,7 +134,7 @@ function DriveDockPanel() {
|
|||||||
{laserAvailable && (
|
{laserAvailable && (
|
||||||
<GPIOToggleControl
|
<GPIOToggleControl
|
||||||
label="Laser"
|
label="Laser"
|
||||||
on={laserState?.laserOn}
|
on={roverState?.laserOn}
|
||||||
disabled={!roverId || roomLightsLockedOn}
|
disabled={!roverId || roomLightsLockedOn}
|
||||||
onToggle={auxControls.setLaser}
|
onToggle={auxControls.setLaser}
|
||||||
keyLabel={laserLabel}
|
keyLabel={laserLabel}
|
||||||
|
|||||||
Reference in New Issue
Block a user