Send color data over the network when calling color update functions
This commit is contained in:
parent
450f438538
commit
39c5aff864
6 changed files with 250 additions and 26 deletions
|
|
@ -289,7 +289,7 @@ void NetworkClient::SendRequest_RGBController_ResizeZone(unsigned int dev_idx, i
|
|||
port.tcp_client_write((char *)&reply_data, sizeof(reply_data));
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
|
||||
|
|
@ -300,15 +300,15 @@ void NetworkClient::SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx)
|
|||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATELEDS;
|
||||
reply_hdr.pkt_size = 0;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, int zone)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
int reply_data[1];
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
|
|
@ -317,18 +317,15 @@ void NetworkClient::SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_id
|
|||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS;
|
||||
reply_hdr.pkt_size = sizeof(reply_data);
|
||||
|
||||
reply_data[0] = zone;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)&reply_data, sizeof(reply_data));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, int led)
|
||||
void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size)
|
||||
{
|
||||
NetPacketHeader reply_hdr;
|
||||
int reply_data[1];
|
||||
|
||||
reply_hdr.pkt_magic[0] = 'O';
|
||||
reply_hdr.pkt_magic[1] = 'R';
|
||||
|
|
@ -337,12 +334,10 @@ void NetworkClient::SendRequest_RGBController_UpdateSingleLED(unsigned int dev_i
|
|||
|
||||
reply_hdr.pkt_dev_idx = dev_idx;
|
||||
reply_hdr.pkt_id = NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED;
|
||||
reply_hdr.pkt_size = sizeof(reply_data);
|
||||
|
||||
reply_data[0] = led;
|
||||
reply_hdr.pkt_size = size;
|
||||
|
||||
port.tcp_client_write((char *)&reply_hdr, sizeof(NetPacketHeader));
|
||||
port.tcp_client_write((char *)&reply_data, sizeof(reply_data));
|
||||
port.tcp_client_write((char *)data, size);
|
||||
}
|
||||
|
||||
void NetworkClient::SendRequest_RGBController_SetCustomMode(unsigned int dev_idx)
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ public:
|
|||
|
||||
void SendRequest_RGBController_ResizeZone(unsigned int dev_idx, int zone, int new_size);
|
||||
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, int zone);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, int led);
|
||||
void SendRequest_RGBController_UpdateLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateZoneLEDs(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
void SendRequest_RGBController_UpdateSingleLED(unsigned int dev_idx, unsigned char * data, unsigned int size);
|
||||
|
||||
void SendRequest_RGBController_SetCustomMode(unsigned int dev_idx);
|
||||
|
||||
|
|
|
|||
|
|
@ -202,6 +202,7 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
controllers[header.pkt_dev_idx]->SetColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateLEDs();
|
||||
}
|
||||
break;
|
||||
|
|
@ -209,12 +210,13 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
case NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS:
|
||||
printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATEZONELEDS\r\n" );
|
||||
|
||||
if((header.pkt_dev_idx < controllers.size()) && (header.pkt_size == sizeof(int)))
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int zone;
|
||||
|
||||
memcpy(&zone, data, sizeof(int));
|
||||
memcpy(&zone, &data[sizeof(unsigned int)], sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetZoneColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateZoneLEDs(zone);
|
||||
}
|
||||
break;
|
||||
|
|
@ -222,12 +224,13 @@ void NetworkServer::ListenThread(SOCKET * client_sock)
|
|||
case NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED:
|
||||
printf( "NET_PACKET_ID_RGBCONTROLLER_UPDATESINGLELED\r\n" );
|
||||
|
||||
if((header.pkt_dev_idx < controllers.size()) && (header.pkt_size == sizeof(int)))
|
||||
if(header.pkt_dev_idx < controllers.size())
|
||||
{
|
||||
int led;
|
||||
|
||||
memcpy(&led, data, sizeof(int));
|
||||
|
||||
controllers[header.pkt_dev_idx]->SetSingleLEDColorDescription((unsigned char *)data);
|
||||
controllers[header.pkt_dev_idx]->UpdateSingleLED(led);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -621,6 +621,11 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf)
|
|||
|
||||
colors.push_back(new_color);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Setup colors |
|
||||
\*---------------------------------------------------------*/
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetModeDescription(int mode)
|
||||
|
|
@ -653,8 +658,6 @@ unsigned char * RGBController::GetModeDescription(int mode)
|
|||
data_size += sizeof(mode_num_colors);
|
||||
data_size += (mode_num_colors * sizeof(RGBColor));
|
||||
|
||||
printf( "Data size: %d \r\n", data_size );
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
@ -753,7 +756,6 @@ unsigned char * RGBController::GetModeDescription(int mode)
|
|||
data_ptr += sizeof(modes[mode].colors[color_index]);
|
||||
}
|
||||
|
||||
printf( "end data_ptr %d\r\n", data_ptr );
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
|
|
@ -868,6 +870,210 @@ void RGBController::SetModeDescription(unsigned char* data_buf)
|
|||
printf("read data ptr %d\r\n", data_ptr);
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetColorDescription()
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short num_colors = colors.size();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(num_colors);
|
||||
data_size += num_colors * sizeof(RGBColor);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &colors[color_index], sizeof(colors[color_index]));
|
||||
data_ptr += sizeof(colors[color_index]);
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
unsigned int data_ptr = sizeof(unsigned int);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short num_colors;
|
||||
memcpy(&num_colors, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
RGBColor new_color;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_color, &data_buf[data_ptr], sizeof(RGBColor));
|
||||
data_ptr += sizeof(RGBColor);
|
||||
|
||||
colors[color_index] = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetZoneColorDescription(int zone)
|
||||
{
|
||||
unsigned int data_ptr = 0;
|
||||
unsigned int data_size = 0;
|
||||
|
||||
unsigned short num_colors = zones[zone].leds_count;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Calculate data size |
|
||||
\*---------------------------------------------------------*/
|
||||
data_size += sizeof(data_size);
|
||||
data_size += sizeof(zone);
|
||||
data_size += sizeof(num_colors);
|
||||
data_size += num_colors * sizeof(RGBColor);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create data buffer |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[data_size];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in data size |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &data_size, sizeof(data_size));
|
||||
data_ptr += sizeof(data_size);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zone, sizeof(zone));
|
||||
data_ptr += sizeof(zone);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &num_colors, sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[data_ptr], &zones[zone].colors[color_index], sizeof(zones[zone].colors[color_index]));
|
||||
data_ptr += sizeof(zones[zone].colors[color_index]);
|
||||
}
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetZoneColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
unsigned int data_ptr = sizeof(unsigned int);
|
||||
unsigned int zone_idx;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in zone index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&zone_idx, &data_buf[data_ptr], sizeof(zone_idx));
|
||||
data_ptr += sizeof(zone_idx);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in number of colors (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short num_colors;
|
||||
memcpy(&num_colors, &data_buf[data_ptr], sizeof(unsigned short));
|
||||
data_ptr += sizeof(unsigned short);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in colors |
|
||||
\*---------------------------------------------------------*/
|
||||
for(int color_index = 0; color_index < num_colors; color_index++)
|
||||
{
|
||||
RGBColor new_color;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in color (data) |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&new_color, &data_buf[data_ptr], sizeof(RGBColor));
|
||||
data_ptr += sizeof(RGBColor);
|
||||
|
||||
zones[zone_idx].colors[color_index] = new_color;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * RGBController::GetSingleLEDColorDescription(int led)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Fixed size descrption: |
|
||||
| int: LED index |
|
||||
| RGBColor: LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char *data_buf = new unsigned char[sizeof(int) + sizeof(RGBColor)];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[0], &led, sizeof(int));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&data_buf[sizeof(led)], &colors[led], sizeof(RGBColor));
|
||||
|
||||
return(data_buf);
|
||||
}
|
||||
|
||||
void RGBController::SetSingleLEDColorDescription(unsigned char* data_buf)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Fixed size descrption: |
|
||||
| int: LED index |
|
||||
| RGBColor: LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
int led_idx;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED index |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&led_idx, &data_buf[0], sizeof(led_idx));
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Copy in LED color |
|
||||
\*---------------------------------------------------------*/
|
||||
memcpy(&colors[led_idx], &data_buf[sizeof(led_idx)], sizeof(RGBColor));
|
||||
}
|
||||
|
||||
void RGBController::SetupColors()
|
||||
{
|
||||
unsigned int total_led_count;
|
||||
|
|
|
|||
|
|
@ -163,6 +163,15 @@ public:
|
|||
unsigned char * GetModeDescription(int mode);
|
||||
void SetModeDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetColorDescription();
|
||||
void SetColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetZoneColorDescription(int zone);
|
||||
void SetZoneColorDescription(unsigned char* data_buf);
|
||||
|
||||
unsigned char * GetSingleLEDColorDescription(int led);
|
||||
void SetSingleLEDColorDescription(unsigned char* data_buf);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Functions to be implemented in device implementation |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -28,17 +28,28 @@ void RGBController_Network::ResizeZone(int zone, int new_size)
|
|||
|
||||
void RGBController_Network::UpdateLEDs()
|
||||
{
|
||||
client->SendRequest_RGBController_UpdateLEDs(dev_idx);
|
||||
unsigned char * data = GetColorDescription();
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
|
||||
client->SendRequest_RGBController_UpdateLEDs(dev_idx, data, size);
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
client->SendRequest_RGBController_UpdateZoneLEDs(dev_idx, zone);
|
||||
unsigned char * data = GetZoneColorDescription(zone);
|
||||
unsigned int size;
|
||||
|
||||
memcpy(&size, &data[0], sizeof(unsigned int));
|
||||
|
||||
client->SendRequest_RGBController_UpdateZoneLEDs(dev_idx, data, size);
|
||||
}
|
||||
|
||||
void RGBController_Network::UpdateSingleLED(int led)
|
||||
{
|
||||
client->SendRequest_RGBController_UpdateSingleLED(dev_idx, led);
|
||||
unsigned char * data = GetSingleLEDColorDescription(led);
|
||||
client->SendRequest_RGBController_UpdateSingleLED(dev_idx, data, sizeof(int) + sizeof(RGBColor));
|
||||
}
|
||||
|
||||
void RGBController_Network::SetCustomMode()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue