Skip to content

Commit

Permalink
Add Serial Console Wifi Scan (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
unlogisch04 authored Feb 16, 2024
1 parent 21576af commit a74d5aa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ settings-serial-factory_reset-warning-cancel = Cancel
settings-serial-get_infos = Get Infos
settings-serial-serial_select = Select a serial port
settings-serial-auto_dropdown_item = Auto
settings-serial-get_wifi_scan = Get WiFi Scan
## OSC router settings
settings-osc-router = OSC router
Expand Down
10 changes: 10 additions & 0 deletions gui/src/components/settings/pages/Serial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SerialTrackerGetInfoRequestT,
SerialTrackerRebootRequestT,
SerialUpdateResponseT,
SerialTrackerGetWifiScanRequestT,
} from 'solarxr-protocol';
import { useElemSize, useLayout } from '@/hooks/layout';
import { useWebsocketAPI } from '@/hooks/websocket-api';
Expand Down Expand Up @@ -158,6 +159,12 @@ export function Serial() {
new SerialTrackerGetInfoRequestT()
);
};
const getWifiScan = () => {
sendRPCPacket(
RpcMessage.SerialTrackerGetWifiScanRequest,
new SerialTrackerGetWifiScanRequestT()
);
};

return (
<>
Expand Down Expand Up @@ -231,6 +238,9 @@ export function Serial() {
<Button variant="quaternary" onClick={getInfos}>
{l10n.getString('settings-serial-get_infos')}
</Button>
<Button variant="quaternary" onClick={getWifiScan}>
{l10n.getString('settings-serial-get_wifi_scan')}
</Button>
{isMobile && (
<Dropdown
control={control}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ class AndroidSerialHandler(val activity: AppCompatActivity) :
writeSerial("GET INFO")
}

override fun wifiScanRequest() {
writeSerial("GET WIFISCAN")
}

override fun closeSerial() {
try {
if (isConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public RPCSerialHandler(RPCHandler rpcHandler, ProtocolAPI api) {
RpcMessage.SerialTrackerFactoryResetRequest,
this::onSerialTrackerFactoryResetRequest
);
rpcHandler
.registerPacketListener(
RpcMessage.SerialTrackerGetWifiScanRequest,
this::onSerialTrackerGetWifiScanRequest
);
rpcHandler.registerPacketListener(RpcMessage.SetWifiRequest, this::onSetWifiRequest);
rpcHandler.registerPacketListener(RpcMessage.OpenSerialRequest, this::onOpenSerialRequest);
rpcHandler
Expand Down Expand Up @@ -158,6 +163,17 @@ public void onSerialTrackerFactoryResetRequest(
this.api.server.serialHandler.factoryResetRequest();
}

public void onSerialTrackerGetWifiScanRequest(
GenericConnection conn,
RpcMessageHeader messageHeader
) {
SerialTrackerGetWifiScanRequest req = (SerialTrackerGetWifiScanRequest) messageHeader
.message(new SerialTrackerGetWifiScanRequest());
if (req == null)
return;

this.api.server.serialHandler.wifiScanRequest();
}

private void onRequestSerialDevices(GenericConnection conn, RpcMessageHeader messageHeader) {
SerialDevicesRequest req = (SerialDevicesRequest) messageHeader
Expand Down
3 changes: 3 additions & 0 deletions server/core/src/main/java/dev/slimevr/serial/SerialHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class SerialHandler {
abstract fun rebootRequest()
abstract fun factoryResetRequest()
abstract fun infoRequest()
abstract fun wifiScanRequest()
abstract fun closeSerial()
abstract fun setWifi(ssid: String, passwd: String)

Expand Down Expand Up @@ -62,6 +63,8 @@ class SerialHandlerStub() : SerialHandler() {

override fun infoRequest() {}

override fun wifiScanRequest() {}

override fun closeSerial() {}

override fun setWifi(ssid: String, passwd: String) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class DesktopSerialHandler : SerialHandler(), SerialPortMessageListener {
writeSerial("GET INFO")
}

override fun wifiScanRequest() {
writeSerial("GET WIFISCAN")
}

@Synchronized
override fun closeSerial() {
try {
Expand Down

0 comments on commit a74d5aa

Please sign in to comment.