From 0cfe5ae0bbde07867ebbb848095d736953ccc5d1 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 2 Jul 2025 14:32:03 -0500 Subject: [PATCH] Add SDK command to rescan devices --- Documentation/OpenRGBSDK.md | 7 +++++++ NetworkProtocol.h | 2 ++ NetworkServer.cpp | 9 +++++++++ NetworkServer.h | 2 ++ 4 files changed, 20 insertions(+) diff --git a/Documentation/OpenRGBSDK.md b/Documentation/OpenRGBSDK.md index a9b5cb77..33862387 100644 --- a/Documentation/OpenRGBSDK.md +++ b/Documentation/OpenRGBSDK.md @@ -51,6 +51,7 @@ The following IDs represent different SDK commands. Each ID packet has a certai | 40 | [NET_PACKET_ID_REQUEST_PROTOCOL_VERSION](#net_packet_id_request_protocol_version) | Request OpenRGB SDK protocol version from server | 1* | | 50 | [NET_PACKET_ID_SET_CLIENT_NAME](#net_packet_id_set_client_name) | Send client name string to server | 0 | | 100 | [NET_PACKET_ID_DEVICE_LIST_UPDATED](#net_packet_id_device_list_updated) | Indicate to clients that device list has updated | 1 | +| 140 | [NET_PACKET_ID_REQUEST_RESCAN_DEVICES](#net_packet_id_request_rescan_devices) | Request server to rescan devices | 5 | | 150 | [NET_PACKET_ID_REQUEST_PROFILE_LIST](#net_packet_id_request_profile_list) | Request profile list | 2 | | 151 | [NET_PACKET_ID_REQUEST_SAVE_PROFILE](#net_packet_id_request_save_profile) | Save current configuration in a new profile | 2 | | 152 | [NET_PACKET_ID_REQUEST_LOAD_PROFILE](#net_packet_id_request_load_profile) | Load a given profile | 2 | @@ -218,6 +219,12 @@ The client uses this ID to send the client's null-terminated name string to the The server uses this ID to notify a client that the server's device list has been updated. Upon receiving this packet, clients should synchronize their local device lists with the server by requesting size and controller data again. This packet contains no data. +## NET_PACKET_ID_REQUEST_RESCAN_DEVICES + +### Client Only [Size: 0] + +The client uses this ID to request the server rescan its devices. + ## NET_PACKET_ID_REQUEST_PROFILE_LIST ### Request [Size: 0] diff --git a/NetworkProtocol.h b/NetworkProtocol.h index b8973954..6719475c 100644 --- a/NetworkProtocol.h +++ b/NetworkProtocol.h @@ -63,6 +63,8 @@ enum NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */ + NET_PACKET_ID_REQUEST_RESCAN_DEVICES = 140, /* Request rescan of devices */ + NET_PACKET_ID_REQUEST_PROFILE_LIST = 150, /* Request profile list */ NET_PACKET_ID_REQUEST_SAVE_PROFILE = 151, /* Save current configuration in a new profile */ NET_PACKET_ID_REQUEST_LOAD_PROFILE = 152, /* Load a given profile */ diff --git a/NetworkServer.cpp b/NetworkServer.cpp index bac94400..30045d50 100644 --- a/NetworkServer.cpp +++ b/NetworkServer.cpp @@ -668,6 +668,10 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info) ProcessRequest_ClientString(client_sock, header.pkt_size, data); break; + case NET_PACKET_ID_REQUEST_RESCAN_DEVICES: + ProcessRequest_RescanDevices(); + break; + case NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE: if(data == NULL) { @@ -1046,6 +1050,11 @@ void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int ClientInfoChanged(); } +void NetworkServer::ProcessRequest_RescanDevices() +{ + ResourceManager::get()->DetectDevices(); +} + void NetworkServer::SendReply_ControllerCount(SOCKET client_sock) { NetPacketHeader reply_hdr; diff --git a/NetworkServer.h b/NetworkServer.h index 8d9f9106..286770a6 100644 --- a/NetworkServer.h +++ b/NetworkServer.h @@ -18,6 +18,7 @@ #include "NetworkProtocol.h" #include "net_port.h" #include "ProfileManager.h" +#include "ResourceManager.h" #define MAXSOCK 32 #define TCP_TIMEOUT_SECONDS 5 @@ -82,6 +83,7 @@ public: void ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data); void ProcessRequest_ClientString(SOCKET client_sock, unsigned int data_size, char * data); + void ProcessRequest_RescanDevices(); void SendReply_ControllerCount(SOCKET client_sock); void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx, unsigned int protocol_version);