mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Add Reboot, Factory Reset and Get infos (#302)
This commit is contained in:
@@ -49,7 +49,7 @@ export function Button({
|
||||
}: {
|
||||
children: ReactChild;
|
||||
icon?: ReactChild;
|
||||
variant: 'primary' | 'secondary' | 'tierciary';
|
||||
variant: 'primary' | 'secondary' | 'tierciary' | 'quaternary';
|
||||
to?: string;
|
||||
loading?: boolean;
|
||||
rounded?: boolean;
|
||||
@@ -75,6 +75,12 @@ export function Button({
|
||||
'bg-background-50 hover:bg-background-50 cursor-not-allowed text-background-40':
|
||||
disabled,
|
||||
}),
|
||||
quaternary: classNames({
|
||||
'bg-background-70 hover:bg-background-60 text-standard text-background-10':
|
||||
!disabled,
|
||||
'bg-background-70 hover:bg-background-70 cursor-not-allowed text-background-40':
|
||||
disabled,
|
||||
}),
|
||||
};
|
||||
return classNames(
|
||||
variantsMap[variant],
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
CloseSerialRequestT,
|
||||
OpenSerialRequestT,
|
||||
RpcMessage,
|
||||
SerialTrackerFactoryResetRequestT,
|
||||
SerialTrackerGetInfoRequestT,
|
||||
SerialTrackerRebootRequestT,
|
||||
SerialUpdateResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useLayout } from '../../../hooks/layout';
|
||||
import { useElemSize, useLayout } from '../../../hooks/layout';
|
||||
import { useWebsocketAPI } from '../../../hooks/websocket-api';
|
||||
import { Button } from '../../commons/Button';
|
||||
import { Typography } from '../../commons/Typography';
|
||||
|
||||
export interface WifiForm {
|
||||
@@ -21,6 +25,9 @@ export function Serial() {
|
||||
ref: consoleRef,
|
||||
} = useLayout<HTMLDivElement>();
|
||||
|
||||
const toolbarRef = useRef<HTMLDivElement>(null);
|
||||
const { height } = useElemSize(toolbarRef);
|
||||
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
// const consoleRef = useRef<HTMLPreElement>(null);
|
||||
const [consoleContent, setConsole] = useState('');
|
||||
@@ -72,27 +79,65 @@ export function Serial() {
|
||||
};
|
||||
}, [isSerialOpen, sendRPCPacket]);
|
||||
|
||||
const reboot = () => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.SerialTrackerRebootRequest,
|
||||
new SerialTrackerRebootRequestT()
|
||||
);
|
||||
};
|
||||
const factoryReset = () => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.SerialTrackerFactoryResetRequest,
|
||||
new SerialTrackerFactoryResetRequestT()
|
||||
);
|
||||
};
|
||||
const getInfos = () => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.SerialTrackerGetInfoRequest,
|
||||
new SerialTrackerGetInfoRequestT()
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full gap-2 flex-grow bg-background-70 p-5 rounded-md">
|
||||
<Typography variant="main-title">Serial Console</Typography>
|
||||
<Typography color="secondary">
|
||||
This is a live information feed for serial communication. May be useful
|
||||
if you need to know the firmware is acting up.
|
||||
</Typography>
|
||||
<div
|
||||
className="w-full bg-background-80 rounded-lg overflow-x-auto overflow-y-auto"
|
||||
ref={consoleRef}
|
||||
style={{ height: layoutHeight }}
|
||||
>
|
||||
<div className="flex flex-col bg-background-70 h-full p-5 rounded-md">
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography variant="main-title">Serial Console</Typography>
|
||||
<Typography color="secondary">
|
||||
This is a live information feed for serial communication.
|
||||
</Typography>
|
||||
<Typography color="secondary">
|
||||
May be useful if you need to know the firmware is acting up.
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="bg-background-80 rounded-lg flex flex-col p-2">
|
||||
<div
|
||||
className="flex select-text "
|
||||
style={{ maxWidth: layoutWidth - 30 }}
|
||||
ref={consoleRef}
|
||||
className="overflow-x-auto overflow-y-auto"
|
||||
style={{
|
||||
height: layoutHeight - height - 30,
|
||||
width: layoutWidth - 24,
|
||||
}}
|
||||
>
|
||||
<pre>
|
||||
{isSerialOpen
|
||||
? consoleContent
|
||||
: 'Connection to serial lost, Reconnecting...'}
|
||||
</pre>
|
||||
<div className="flex select-text px-3">
|
||||
<pre>
|
||||
{isSerialOpen
|
||||
? consoleContent
|
||||
: 'Connection to serial lost, Reconnecting...'}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div className="" ref={toolbarRef}>
|
||||
<div className="border-t-2 pt-2 border-background-60 border-solid m-2 gap-2 flex flex-row">
|
||||
<Button variant="quaternary" onClick={reboot}>
|
||||
Reboot
|
||||
</Button>
|
||||
<Button variant="quaternary" onClick={factoryReset}>
|
||||
Factory Reset
|
||||
</Button>
|
||||
<Button variant="quaternary" onClick={getInfos}>
|
||||
Get Infos
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -651,24 +651,6 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
|
||||
return;
|
||||
|
||||
this.api.server.getSerialHandler().rebootRequest();
|
||||
|
||||
this.api.getAPIServers().forEach((server) -> {
|
||||
server
|
||||
.getAPIConnections()
|
||||
.filter(conn2 -> conn2.getContext().useSerial())
|
||||
.forEach((conn2) -> {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
|
||||
SerialUpdateResponse.startSerialUpdateResponse(fbb);
|
||||
SerialUpdateResponse.addClosed(fbb, false);
|
||||
int update = SerialUpdateResponse.endSerialUpdateResponse(fbb);
|
||||
int outbound = this
|
||||
.createRPCMessage(fbb, RpcMessage.SerialUpdateResponse, update);
|
||||
fbb.finish(outbound);
|
||||
|
||||
conn2.send(fbb.dataBuffer());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void SerialTrackerGetInfoRequest(
|
||||
@@ -681,24 +663,6 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
|
||||
return;
|
||||
|
||||
this.api.server.getSerialHandler().infoRequest();
|
||||
|
||||
this.api.getAPIServers().forEach((server) -> {
|
||||
server
|
||||
.getAPIConnections()
|
||||
.filter(conn2 -> conn2.getContext().useSerial())
|
||||
.forEach((conn2) -> {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
|
||||
SerialUpdateResponse.startSerialUpdateResponse(fbb);
|
||||
SerialUpdateResponse.addClosed(fbb, false);
|
||||
int update = SerialUpdateResponse.endSerialUpdateResponse(fbb);
|
||||
int outbound = this
|
||||
.createRPCMessage(fbb, RpcMessage.SerialUpdateResponse, update);
|
||||
fbb.finish(outbound);
|
||||
|
||||
conn2.send(fbb.dataBuffer());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void SerialTrackerFactoryResetRequest(
|
||||
@@ -711,24 +675,6 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
|
||||
return;
|
||||
|
||||
this.api.server.getSerialHandler().factoryResetRequest();
|
||||
|
||||
this.api.getAPIServers().forEach((server) -> {
|
||||
server
|
||||
.getAPIConnections()
|
||||
.filter(conn2 -> conn2.getContext().useSerial())
|
||||
.forEach((conn2) -> {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
|
||||
SerialUpdateResponse.startSerialUpdateResponse(fbb);
|
||||
SerialUpdateResponse.addClosed(fbb, false);
|
||||
int update = SerialUpdateResponse.endSerialUpdateResponse(fbb);
|
||||
int outbound = this
|
||||
.createRPCMessage(fbb, RpcMessage.SerialUpdateResponse, update);
|
||||
fbb.finish(outbound);
|
||||
|
||||
conn2.send(fbb.dataBuffer());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user