Implement requests for number of controllers and controller information block
This commit is contained in:
parent
c7ffe3b926
commit
7af283fdbf
1 changed files with 45 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "NetworkServer.h"
|
||||
#include <cstring>
|
||||
|
||||
//Include thread libraries for Windows or Linux
|
||||
#ifdef WIN32
|
||||
|
|
@ -98,7 +99,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
//Read first byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = recv(*client_sock, &header.pkt_magic[0], 1, 0);
|
||||
bytes_read = read(*client_sock, &header.pkt_magic[0], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test first character of magic - 'O'
|
||||
|
|
@ -112,7 +113,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
//Read second byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = recv(*client_sock, &header.pkt_magic[1], 1, 0);
|
||||
bytes_read = read(*client_sock, &header.pkt_magic[1], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test second character of magic - 'R'
|
||||
|
|
@ -126,7 +127,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
//Read third byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = recv(*client_sock, &header.pkt_magic[2], 1, 0);
|
||||
bytes_read = read(*client_sock, &header.pkt_magic[2], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test third character of magic - 'G'
|
||||
|
|
@ -140,7 +141,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
//Read fourth byte of magic
|
||||
do
|
||||
{
|
||||
bytes_read = recv(*client_sock, &header.pkt_magic[3], 1, 0);
|
||||
bytes_read = read(*client_sock, &header.pkt_magic[3], 1);
|
||||
} while(bytes_read == 0);
|
||||
|
||||
//Test fourth character of magic - 'B'
|
||||
|
|
@ -155,7 +156,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
bytes_read = 0;
|
||||
do
|
||||
{
|
||||
bytes_read += recv(*client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read, 0);
|
||||
bytes_read += read(*client_sock, (char *)&header.pkt_dev_idx + bytes_read, sizeof(header) - sizeof(header.pkt_magic) - bytes_read);
|
||||
} while(bytes_read != sizeof(header) - sizeof(header.pkt_magic));
|
||||
|
||||
printf( "Received header, now receiving data of size %d\r\n", header.pkt_size);
|
||||
|
|
@ -169,7 +170,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
|
||||
do
|
||||
{
|
||||
bytes_read += recv(*client_sock, &data[bytes_read], 128, 0);
|
||||
bytes_read += read(*client_sock, &data[bytes_read], 128);
|
||||
} while (bytes_read < header.pkt_size);
|
||||
}
|
||||
|
||||
|
|
@ -181,10 +182,48 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
{
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_COUNT:
|
||||
printf( "NET_PACKET_ID_REQUEST_CONTROLLER_COUNT\r\n" );
|
||||
|
||||
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_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = sizeof(unsigned int);
|
||||
|
||||
reply_data = controllers.size();
|
||||
|
||||
write(*client_sock, &reply_hdr, sizeof(NetPacketHeader));
|
||||
write(*client_sock, &reply_data, sizeof(unsigned int));
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_REQUEST_CONTROLLER_DATA:
|
||||
printf( "NET_PACKET_ID_REQUEST_CONTROLLER_DATA\r\n" );
|
||||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
unsigned char *reply_data = controllers[header.pkt_dev_idx]->GetDeviceDescription();
|
||||
unsigned int reply_size;
|
||||
|
||||
memcpy(&reply_size, reply_data, sizeof(reply_size));
|
||||
|
||||
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_CONTROLLER_COUNT;
|
||||
reply_hdr.pkt_size = reply_size;
|
||||
|
||||
write(*client_sock, &reply_hdr, sizeof(NetPacketHeader));
|
||||
write(*client_sock, reply_data, reply_size);
|
||||
}
|
||||
break;
|
||||
|
||||
case NET_PACKET_ID_RGBCONTROLLER_RESIZEZONE:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue