Add grouping for unicast E1.31 devices

This commit is contained in:
Der Informatiker 2022-03-31 12:37:52 +02:00
parent b2c6028cb8
commit 2c1c80334b
2 changed files with 46 additions and 53 deletions

View file

@ -24,7 +24,7 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
{
json e131_settings;
std::vector<std::vector<E131Device>> device_lists;
std::vector<std::vector<E131Device>> device_lists;
E131Device dev;
/*-------------------------------------------------*\
@ -216,69 +216,58 @@ void DetectE131Controllers(std::vector<RGBController*> &rgb_controllers)
bool device_added_to_existing_list = false;
/*---------------------------------------------------------*\
| Only track grouping for multicast controllers. Unicast |
| controllers are currently not grouped. |
| Track grouping for all controllers. |
\*---------------------------------------------------------*/
if(dev.ip == "")
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
{
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
{
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
{
/*---------------------------------------------------------*\
| Determine if there is any overlap between this device and |
| any existing device list |
| Offset the end by two - one because the range is 1-512 |
| rather than 0-511, and one because the start channel is |
| included in the first set of 3 channels. |
\*---------------------------------------------------------*/
unsigned int dev_start = dev.start_universe;
unsigned int list_start = device_lists[list_idx][device_idx].start_universe;
unsigned int dev_end = dev.start_universe + ((dev.start_channel + (3 * dev.num_leds) - 2) / 512);
unsigned int list_end = device_lists[list_idx][device_idx].start_universe + ((device_lists[list_idx][device_idx].start_channel + (3 * device_lists[list_idx][device_idx].num_leds) - 2) / 512);
bool overlap = !(dev_end < list_start || list_end < dev_start);
/*---------------------------------------------------------*\
| Check if any universes used by this new device exist in |
| the existing device. If so, add the new device to the |
| existing list. |
\*---------------------------------------------------------*/
if(overlap)
{
device_lists[list_idx].push_back(dev);
device_added_to_existing_list = true;
break;
}
}
if(device_added_to_existing_list)
/*---------------------------------------------------------*\
| Determine if there is any overlap between this device and |
| any existing device list |
| Offset the end by two - one because the range is 1-512 |
| rather than 0-511, and one because the start channel is |
| included in the first set of 3 channels. |
\*---------------------------------------------------------*/
unsigned int dev_start = dev.start_universe;
unsigned int list_start = device_lists[list_idx][device_idx].start_universe;
unsigned int dev_end = dev.start_universe + ((dev.start_channel + (3 * dev.num_leds) - 2) / 512);
unsigned int list_end = device_lists[list_idx][device_idx].start_universe + ((device_lists[list_idx][device_idx].start_channel + (3 * device_lists[list_idx][device_idx].num_leds) - 2) / 512);
std::string dev_ip = dev.ip;
std::string list_ip = device_lists[list_idx][device_idx].ip;
bool overlap = dev_ip == list_ip && !(dev_end < list_start || list_end < dev_start);
/*---------------------------------------------------------*\
| Check if any universes used by this new device exist in |
| the existing device. If so, add the new device to the |
| existing list. |
\*---------------------------------------------------------*/
if(overlap)
{
device_lists[list_idx].push_back(dev);
device_added_to_existing_list = true;
break;
}
}
/*---------------------------------------------------------*\
| If the device did not overlap with existing devices, |
| create a new list for it |
\*---------------------------------------------------------*/
if(!device_added_to_existing_list)
if(device_added_to_existing_list)
{
std::vector<E131Device> new_list;
new_list.push_back(dev);
device_lists.push_back(new_list);
break;
}
}
else
{
std::vector<E131Device> tmp_device_list;
tmp_device_list.push_back(dev);
RGBController_E131* rgb_controller;
rgb_controller = new RGBController_E131(tmp_device_list);
rgb_controllers.push_back(rgb_controller);
/*---------------------------------------------------------*\
| If the device did not overlap with existing devices, |
| create a new list for it |
\*---------------------------------------------------------*/
if(!device_added_to_existing_list)
{
std::vector<E131Device> new_list;
new_list.push_back(dev);
device_lists.push_back(new_list);
}
}

View file

@ -33,12 +33,16 @@ RGBController_E131::RGBController_E131(std::vector<E131Device> device_list)
{
name = devices[0].name;
}
else if(devices[0].ip != "")
{
name += " (" + devices[0].ip + ")";
}
/*-----------------------------------------*\
| Append the destination address to the |
| location field |
\*-----------------------------------------*/
if((devices.size() == 1) && (devices[0].ip != ""))
if(devices[0].ip != "")
{
location += "Unicast " + devices[0].ip + ", ";
}