mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-23 23:37:48 -05:00
SDK protocol versioning implemented. Protocol updated to version 1 which adds vendor string to controller request.
This commit is contained in:
@@ -72,6 +72,22 @@ unsigned short NetworkClient::GetPort()
|
||||
return port_num;
|
||||
}
|
||||
|
||||
unsigned int NetworkClient::GetProtocolVersion()
|
||||
{
|
||||
unsigned int protocol_version = 0;
|
||||
|
||||
if(server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION)
|
||||
{
|
||||
protocol_version = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol_version = server_protocol_version;
|
||||
}
|
||||
|
||||
return(protocol_version);
|
||||
}
|
||||
|
||||
bool NetworkClient::GetConnected()
|
||||
{
|
||||
return(server_connected);
|
||||
@@ -203,13 +219,38 @@ void NetworkClient::ConnectionThreadFunction()
|
||||
|
||||
if(server_initialized == false && server_connected == true)
|
||||
{
|
||||
unsigned int timeout_counter = 0;
|
||||
requested_controllers = 0;
|
||||
server_controller_count = 0;
|
||||
server_controller_count_received = false;
|
||||
server_protocol_version_received = false;
|
||||
|
||||
//Wait for server to connect
|
||||
std::this_thread::sleep_for(100ms);
|
||||
|
||||
//Request protocol version
|
||||
SendRequest_ProtocolVersion();
|
||||
|
||||
//Wait up to 1s for protocol version reply
|
||||
|
||||
while(!server_protocol_version_received)
|
||||
{
|
||||
std::this_thread::sleep_for(5ms);
|
||||
|
||||
timeout_counter++;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If no protocol version received within 1s, assume |
|
||||
| the server doesn't support protocol versioning |
|
||||
| and use protocol version 0 |
|
||||
\*-------------------------------------------------*/
|
||||
if(timeout_counter > 200)
|
||||
{
|
||||
server_protocol_version = 0;
|
||||
server_protocol_version_received = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Once server is connected, send client string
|
||||
SendData_ClientString();
|
||||
|
||||
@@ -412,6 +453,10 @@ void NetworkClient::ListenThreadFunction()
|
||||
ProcessReply_ControllerData(header.pkt_size, data, header.pkt_dev_idx);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_PROTOCOL_VERSION:
|
||||
ProcessReply_ProtocolVersion(header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_DEVICE_LIST_UPDATED:
|
||||
ProcessRequest_DeviceListChanged();
|
||||
break;
|
||||
@@ -481,9 +526,9 @@ void NetworkClient::ProcessReply_ControllerCount(unsigned int data_size, char *
|
||||
|
||||
void NetworkClient::ProcessReply_ControllerData(unsigned int /*data_size*/, char * data, unsigned int dev_idx)
|
||||
{
|
||||
RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
|
||||
RGBController_Network * new_controller = new RGBController_Network(this, dev_idx);
|
||||
|
||||
new_controller->ReadDeviceDescription((unsigned char *)data);
|
||||
new_controller->ReadDeviceDescription((unsigned char *)data, GetProtocolVersion());
|
||||
|
||||
ControllerListMutex.lock();
|
||||
|
||||
@@ -502,6 +547,15 @@ void NetworkClient::ProcessReply_ControllerData(unsigned int /*data_size*/, char
|
||||
controller_data_received = true;
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessReply_ProtocolVersion(unsigned int data_size, char * data)
|
||||
{
|
||||
if(data_size == sizeof(unsigned int))
|
||||
{
|
||||
memcpy(&server_protocol_version, data, sizeof(unsigned int));
|
||||
server_protocol_version_received = true;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::ProcessRequest_DeviceListChanged()
|
||||
{
|
||||
change_in_progress = true;
|
||||
@@ -563,36 +617,81 @@ void NetworkClient::SendData_ClientString()
|
||||
|
||||
void NetworkClient::SendRequest_ControllerCount()
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = 0;
|
||||
request_hdr.pkt_dev_idx = 0;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_COUNT;
|
||||
request_hdr.pkt_size = 0;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ControllerData(unsigned int dev_idx)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
unsigned int protocol_version;
|
||||
|
||||
controller_data_received = false;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
reply_hdr.pkt_size = 0;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_REQUEST_CONTROLLER_DATA;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
if(server_protocol_version == 0)
|
||||
{
|
||||
request_hdr.pkt_size = 0;
|
||||
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
request_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Limit the protocol version to the highest supported by both |
|
||||
| the client and the server. |
|
||||
\*-------------------------------------------------------------*/
|
||||
if(server_protocol_version > OPENRGB_SDK_PROTOCOL_VERSION)
|
||||
{
|
||||
protocol_version = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
}
|
||||
else
|
||||
{
|
||||
protocol_version = server_protocol_version;
|
||||
}
|
||||
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&protocol_version, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_ProtocolVersion()
|
||||
{
|
||||
NetPacketHeader request_hdr;
|
||||
unsigned int request_data;
|
||||
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
request_hdr.pkt_dev_idx = 0;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_REQUEST_PROTOCOL_VERSION;
|
||||
request_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
request_data = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_data, sizeof(unsigned int), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size)
|
||||
@@ -602,23 +701,23 @@ void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, i
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
int reply_data[2];
|
||||
NetPacketHeader request_hdr;
|
||||
int request_data[2];
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE;
|
||||
reply_hdr.pkt_size = sizeof(reply_data);
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE;
|
||||
request_hdr.pkt_size = sizeof(request_data);
|
||||
|
||||
reply_data[0] = zone;
|
||||
reply_data[1] = new_size;
|
||||
request_data[0] = zone;
|
||||
request_data[1] = new_size;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&reply_data, sizeof(reply_data), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_data, sizeof(request_data), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
@@ -628,18 +727,18 @@ void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, u
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
|
||||
request_hdr.pkt_size = size;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, 0);
|
||||
}
|
||||
|
||||
@@ -650,18 +749,18 @@ void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_id
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
|
||||
reply_hdr.pkt_size = size;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
|
||||
request_hdr.pkt_size = size;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
@@ -672,18 +771,18 @@ void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_i
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
|
||||
reply_hdr.pkt_size = size;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
|
||||
request_hdr.pkt_size = size;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
@@ -694,18 +793,18 @@ void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE;
|
||||
reply_hdr.pkt_size = 0;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_SETCUSTOMMODE;
|
||||
request_hdr.pkt_size = 0;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
@@ -715,17 +814,17 @@ void NetworkClient::SendRequest_RGBController_UpdateMode(unsigned int dev_idx, u
|
||||
return;
|
||||
}
|
||||
|
||||
NetPacketHeader reply_hdr;
|
||||
NetPacketHeader request_hdr;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
request_hdr.pkt_magic[0] = 'O';
|
||||
request_hdr.pkt_magic[1] = 'R';
|
||||
request_hdr.pkt_magic[2] = 'G';
|
||||
request_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE;
|
||||
reply_hdr.pkt_size = size;
|
||||
request_hdr.pkt_dev_idx = dev_idx;
|
||||
request_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEMODE;
|
||||
request_hdr.pkt_size = size;
|
||||
|
||||
send(client_sock, (char *)&reply_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)&request_hdr, sizeof(NetPacketHeader), MSG_NOSIGNAL);
|
||||
send(client_sock, (char *)data, size, MSG_NOSIGNAL);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
bool GetConnected();
|
||||
const char * GetIP();
|
||||
unsigned short GetPort();
|
||||
unsigned int GetProtocolVersion();
|
||||
bool GetOnline();
|
||||
|
||||
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
|
||||
@@ -46,12 +47,15 @@ public:
|
||||
|
||||
void ProcessReply_ControllerCount(unsigned int data_size, char * data);
|
||||
void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx);
|
||||
void ProcessReply_ProtocolVersion(unsigned int data_size, char * data);
|
||||
|
||||
void ProcessRequest_DeviceListChanged();
|
||||
|
||||
void SendData_ClientString();
|
||||
|
||||
void SendRequest_ControllerCount();
|
||||
void SendRequest_ControllerData(unsigned int dev_idx);
|
||||
void SendRequest_ProtocolVersion();
|
||||
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
@@ -83,6 +87,8 @@ private:
|
||||
bool server_initialized;
|
||||
unsigned int server_controller_count;
|
||||
bool server_controller_count_received;
|
||||
unsigned int server_protocol_version;
|
||||
bool server_protocol_version_received;
|
||||
bool change_in_progress;
|
||||
|
||||
std::thread * ConnectionThread;
|
||||
|
||||
@@ -8,10 +8,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/*-----------------------------------------*\
|
||||
| Default OpenRGB SDK port is 6742 |
|
||||
| This is "ORGB" on a phone keypad |
|
||||
\*-----------------------------------------*/
|
||||
/*-----------------------------------------------------*\
|
||||
| OpenRGB SDK protocol version |
|
||||
| |
|
||||
| 0: Initial (unversioned) protocol |
|
||||
| 1: Add versioning, vendor string (Release 0.5) |
|
||||
\*-----------------------------------------------------*/
|
||||
#define OPENRGB_SDK_PROTOCOL_VERSION 1
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Default OpenRGB SDK port is 6742 |
|
||||
| This is "ORGB" on a phone keypad |
|
||||
\*-----------------------------------------------------*/
|
||||
#define OPENRGB_SDK_PORT 6742
|
||||
|
||||
typedef struct NetPacketHeader
|
||||
@@ -30,6 +38,8 @@ enum
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_COUNT = 0, /* Request RGBController device count from server */
|
||||
NET_PACKET_ID_REQUEST_CONTROLLER_DATA = 1, /* Request RGBController data block */
|
||||
|
||||
NET_PACKET_ID_REQUEST_PROTOCOL_VERSION = 40, /* Request OpenRGB SDK protocol version from server */
|
||||
|
||||
NET_PACKET_ID_SET_CLIENT_NAME = 50, /* Send client name string to server */
|
||||
|
||||
NET_PACKET_ID_DEVICE_LIST_UPDATED = 100, /* Indicate to clients that device list has updated */
|
||||
|
||||
@@ -127,6 +127,26 @@ const char * NetworkServer::GetClientIP(unsigned int client_num)
|
||||
return result;
|
||||
}
|
||||
|
||||
unsigned int NetworkServer::GetClientProtocolVersion(unsigned int client_num)
|
||||
{
|
||||
unsigned int result;
|
||||
|
||||
ServerClientsMutex.lock();
|
||||
|
||||
if(client_num < ServerClients.size())
|
||||
{
|
||||
result = ServerClients[client_num]->client_protocol_version;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
ServerClientsMutex.unlock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void NetworkServer::RegisterClientInfoChangeCallback(NetServerCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
ClientInfoChangeCallbacks.push_back(new_callback);
|
||||
@@ -482,7 +502,21 @@ void NetworkServer::ListenThreadFunction(NetworkClientInfo * client_info)
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
SendReply_ControllerData(client_sock, header.pkt_dev_idx);
|
||||
{
|
||||
unsigned int protocol_version = 0;
|
||||
|
||||
if(header.pkt_size == sizeof(unsigned int))
|
||||
{
|
||||
memcpy(&protocol_version, data, sizeof(unsigned int));
|
||||
}
|
||||
|
||||
SendReply_ControllerData(client_sock, header.pkt_dev_idx, protocol_version);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_PROTOCOL_VERSION:
|
||||
SendReply_ProtocolVersion(client_sock);
|
||||
ProcessRequest_ClientProtocolVersion(client_sock, header.pkt_size, data);
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_SET_CLIENT_NAME:
|
||||
@@ -609,6 +643,37 @@ listen_done:
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientProtocolVersion(SOCKET client_sock, unsigned int data_size, char * data)
|
||||
{
|
||||
unsigned int protocol_version = 0;
|
||||
|
||||
if(data_size == sizeof(unsigned int) && (data != NULL))
|
||||
{
|
||||
memcpy(&protocol_version, data, sizeof(unsigned int));
|
||||
}
|
||||
|
||||
if(protocol_version > OPENRGB_SDK_PROTOCOL_VERSION)
|
||||
{
|
||||
protocol_version = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
}
|
||||
|
||||
ServerClientsMutex.lock();
|
||||
for(unsigned int this_idx = 0; this_idx < ServerClients.size(); this_idx++)
|
||||
{
|
||||
if(ServerClients[this_idx]->client_sock == client_sock)
|
||||
{
|
||||
ServerClients[this_idx]->client_protocol_version = protocol_version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ServerClientsMutex.unlock();
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Client info has changed, call the callbacks |
|
||||
\*-------------------------------------------------*/
|
||||
ClientInfoChanged();
|
||||
}
|
||||
|
||||
void NetworkServer::ProcessRequest_ClientString(SOCKET client_sock, unsigned int /*data_size*/, char * data)
|
||||
{
|
||||
ServerClientsMutex.lock();
|
||||
@@ -648,12 +713,12 @@ void NetworkServer::SendReply_ControllerCount(SOCKET client_sock)
|
||||
send(client_sock, (const char *)&reply_data, sizeof(unsigned int), 0);
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx)
|
||||
void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx, unsigned int protocol_version)
|
||||
{
|
||||
if(dev_idx < controllers.size())
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned char *reply_data = controllers[dev_idx]->GetDeviceDescription();
|
||||
unsigned char *reply_data = controllers[dev_idx]->GetDeviceDescription(protocol_version);
|
||||
unsigned int reply_size;
|
||||
|
||||
memcpy(&reply_size, reply_data, sizeof(reply_size));
|
||||
@@ -672,6 +737,26 @@ void NetworkServer::SendReply_ControllerData(SOCKET client_sock, unsigned int de
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkServer::SendReply_ProtocolVersion(SOCKET client_sock)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned int reply_data;
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
reply_hdr.pkt_magic[2] = 'G';
|
||||
reply_hdr.pkt_magic[3] = 'B';
|
||||
|
||||
reply_hdr.pkt_dev_idx = 0;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_REQUEST_PROTOCOL_VERSION;
|
||||
reply_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
reply_data = OPENRGB_SDK_PROTOCOL_VERSION;
|
||||
|
||||
send(client_sock, (const char *)&reply_hdr, sizeof(NetPacketHeader), 0);
|
||||
send(client_sock, (const char *)&reply_data, sizeof(unsigned int), 0);
|
||||
}
|
||||
|
||||
void NetworkServer::SendRequest_DeviceListChanged(SOCKET client_sock)
|
||||
{
|
||||
NetPacketHeader pkt_hdr;
|
||||
|
||||
@@ -23,6 +23,7 @@ struct NetworkClientInfo
|
||||
SOCKET client_sock;
|
||||
std::thread * client_listen_thread;
|
||||
std::string client_string;
|
||||
unsigned int client_protocol_version;
|
||||
char client_ip[INET_ADDRSTRLEN];
|
||||
};
|
||||
|
||||
@@ -37,6 +38,7 @@ public:
|
||||
unsigned int GetNumClients();
|
||||
const char * GetClientString(unsigned int client_num);
|
||||
const char * GetClientIP(unsigned int client_num);
|
||||
unsigned int GetClientProtocolVersion(unsigned int client_num);
|
||||
|
||||
void ClientInfoChanged();
|
||||
void DeviceListChanged();
|
||||
@@ -50,10 +52,12 @@ public:
|
||||
void ConnectionThreadFunction();
|
||||
void ListenThreadFunction(NetworkClientInfo * client_sock);
|
||||
|
||||
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 SendReply_ControllerCount(SOCKET client_sock);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx);
|
||||
void SendReply_ControllerData(SOCKET client_sock, unsigned int dev_idx, unsigned int protocol_version);
|
||||
void SendReply_ProtocolVersion(SOCKET client_sock);
|
||||
|
||||
void SendRequest_DeviceListChanged(SOCKET client_sock);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ bool ProfileManager::SaveProfile(std::string profile_name)
|
||||
\*---------------------------------------------------------*/
|
||||
for(std::size_t controller_index = 0; controller_index < controllers.size(); controller_index++)
|
||||
{
|
||||
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription();
|
||||
unsigned char *controller_data = controllers[controller_index]->GetDeviceDescription(0);
|
||||
unsigned int controller_size;
|
||||
|
||||
memcpy(&controller_size, controller_data, sizeof(controller_size));
|
||||
@@ -130,7 +130,7 @@ std::vector<RGBController*> ProfileManager::LoadProfileToList
|
||||
|
||||
RGBController_Dummy *temp_controller = new RGBController_Dummy();
|
||||
|
||||
temp_controller->ReadDeviceDescription(controller_data);
|
||||
temp_controller->ReadDeviceDescription(controller_data, 0);
|
||||
|
||||
temp_controllers.push_back(temp_controller);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ RGBController::~RGBController()
|
||||
delete DeviceCallThread;
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetDeviceDescription()
|
||||
unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_version)
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
@@ -25,6 +25,7 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short name_len = strlen(name.c_str()) + 1;
|
||||
unsigned short vendor_len = strlen(vendor.c_str()) + 1;
|
||||
unsigned short description_len = strlen(description.c_str()) + 1;
|
||||
unsigned short version_len = strlen(version.c_str()) + 1;
|
||||
unsigned short serial_len = strlen(serial.c_str()) + 1;
|
||||
@@ -44,6 +45,12 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(device_type);
|
||||
data_size += name_len + sizeof(name_len);
|
||||
|
||||
if(protocol_version >= 1)
|
||||
{
|
||||
data_size += vendor_len + sizeof(vendor_len);
|
||||
}
|
||||
|
||||
data_size += description_len + sizeof(description_len);
|
||||
data_size += version_len + sizeof(version_len);
|
||||
data_size += serial_len + sizeof(serial_len);
|
||||
@@ -136,6 +143,18 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
strcpy((char *)&data_buf[data_ptr], name.c_str());
|
||||
data_ptr += name_len;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in vendor (size+data) if protocol 1 or higher |
|
||||
\*---------------------------------------------------------*/
|
||||
if(protocol_version >= 1)
|
||||
{
|
||||
memcpy(&data_buf[data_ptr], &vendor_len, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
strcpy((char *)&data_buf[data_ptr], vendor.c_str());
|
||||
data_ptr += vendor_len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in description (size+data) |
|
||||
\*---------------------------------------------------------*/
|
||||
@@ -405,7 +424,7 @@ unsigned char * RGBController::GetDeviceDescription()
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::ReadDeviceDescription(unsigned char* data_buf)
|
||||
void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version)
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
|
||||
@@ -427,6 +446,19 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf)
|
||||
name = (char *)&data_buf[data_ptr];
|
||||
data_ptr += name_len;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in vendor if profile version is 1 or higher |
|
||||
\*---------------------------------------------------------*/
|
||||
if(protocol_version >= 1)
|
||||
{
|
||||
unsigned short vendor_len;
|
||||
memcpy(&vendor_len, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
vendor = (char *)&data_buf[data_ptr];
|
||||
data_ptr += vendor_len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in description |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
@@ -179,8 +179,8 @@ public:
|
||||
int GetMode();
|
||||
void SetMode(int mode);
|
||||
|
||||
unsigned char * GetDeviceDescription();
|
||||
void ReadDeviceDescription(unsigned char* data_buf);
|
||||
unsigned char * GetDeviceDescription(unsigned int protocol_version);
|
||||
void ReadDeviceDescription(unsigned char* data_buf, unsigned int protocol_version);
|
||||
|
||||
unsigned char * GetModeDescription(int mode);
|
||||
void SetModeDescription(unsigned char* data_buf);
|
||||
|
||||
5
main.cpp
5
main.cpp
@@ -85,6 +85,11 @@ bool AttemptLocalConnection(std::vector<RGBController*> &rgb_controllers)
|
||||
bool success = false;
|
||||
|
||||
NetworkClient * client = new NetworkClient(rgb_controllers);
|
||||
|
||||
std::string titleString = "OpenRGB ";
|
||||
titleString.append(VERSION_STRING);
|
||||
|
||||
client->SetName(titleString.c_str());
|
||||
client->StartClient();
|
||||
|
||||
for(int timeout = 0; timeout < 10; timeout++)
|
||||
|
||||
@@ -73,11 +73,12 @@ void OpenRGBClientInfoPage::UpdateInfo()
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up the tree view header |
|
||||
\*-----------------------------------------------------*/
|
||||
ui->ClientTree->setColumnCount(2);
|
||||
ui->ClientTree->setColumnCount(3);
|
||||
ui->ClientTree->header()->setStretchLastSection(false);
|
||||
ui->ClientTree->header()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
ui->ClientTree->setColumnWidth(1, 100);
|
||||
ui->ClientTree->setHeaderLabels(QStringList() << "Connected Clients" << "");
|
||||
ui->ClientTree->setColumnWidth(2, 100);
|
||||
ui->ClientTree->setHeaderLabels(QStringList() << "Connected Clients" << "Protocol Version" << "");
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up a signal mapper to handle disconnect buttons |
|
||||
@@ -92,17 +93,18 @@ void OpenRGBClientInfoPage::UpdateInfo()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the top level tree widget items and display the|
|
||||
| client IP addresses in them |
|
||||
| client IP addresses and protocol versions in them |
|
||||
\*-----------------------------------------------------*/
|
||||
QTreeWidgetItem* new_top_item = new QTreeWidgetItem(ui->ClientTree);
|
||||
new_top_item->setText(0, QString::fromStdString(ResourceManager::get()->GetClients()[client_idx]->GetIP()));
|
||||
new_top_item->setText(1, QString::number(ResourceManager::get()->GetClients()[client_idx]->GetProtocolVersion()));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Create the disconnect buttons and connect them to the |
|
||||
| signal mapper |
|
||||
\*-----------------------------------------------------*/
|
||||
QPushButton* new_button = new QPushButton( "Disconnect" );
|
||||
ui->ClientTree->setItemWidget(new_top_item, 1, new_button);
|
||||
ui->ClientTree->setItemWidget(new_top_item, 2, new_button);
|
||||
|
||||
connect(new_button, SIGNAL(clicked()), signalMapper, SLOT(map()));
|
||||
|
||||
|
||||
@@ -47,14 +47,15 @@ void OpenRGBServerInfoPage::UpdateInfo()
|
||||
}
|
||||
|
||||
ui->ServerClientTree->clear();
|
||||
ui->ServerClientTree->setColumnCount(2);
|
||||
ui->ServerClientTree->setHeaderLabels(QStringList() << "Client IP" << "Client Name");
|
||||
ui->ServerClientTree->setColumnCount(3);
|
||||
ui->ServerClientTree->setHeaderLabels(QStringList() << "Client IP" << "Protocol Version" << "Client Name");
|
||||
for(unsigned int client_idx = 0; client_idx < network_server->GetNumClients(); client_idx++)
|
||||
{
|
||||
QTreeWidgetItem * new_item = new QTreeWidgetItem();
|
||||
|
||||
new_item->setText(0, network_server->GetClientIP(client_idx));
|
||||
new_item->setText(1, network_server->GetClientString(client_idx));
|
||||
new_item->setText(1, QString::number(network_server->GetClientProtocolVersion(client_idx)));
|
||||
new_item->setText(2, network_server->GetClientString(client_idx));
|
||||
|
||||
ui->ServerClientTree->addTopLevelItem(new_item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user