SDK protocol versioning implemented. Protocol updated to version 1 which adds vendor string to controller request.
This commit is contained in:
parent
b0de49a107
commit
72da8f362c
11 changed files with 343 additions and 99 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue