From 9bde1c282a21d2db1d0212b0a6bca352138f47ce Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 2 Dec 2020 17:20:30 -0600 Subject: [PATCH] Initial E1.31 Unicast support, add ip parameter to E1.31 device to use Unicast mode --- .../E131Controller/E131ControllerDetect.cpp | 66 ++++++++++++------- .../E131Controller/RGBController_E131.cpp | 24 ++++++- .../E131Controller/RGBController_E131.h | 1 + 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/Controllers/E131Controller/E131ControllerDetect.cpp b/Controllers/E131Controller/E131ControllerDetect.cpp index 130fd741..27c2a3b4 100644 --- a/Controllers/E131Controller/E131ControllerDetect.cpp +++ b/Controllers/E131Controller/E131ControllerDetect.cpp @@ -43,6 +43,7 @@ void DetectE131Controllers(std::vector &rgb_controllers) | Clear E1.31 device data | \*-------------------------------------------------*/ dev.name = ""; + dev.ip = ""; dev.type = ZONE_TYPE_SINGLE; dev.num_leds = 0; dev.rgb_order = E131_RGB_ORDER_RBG; @@ -57,6 +58,11 @@ void DetectE131Controllers(std::vector &rgb_controllers) dev.name = e131_settings["devices"][device_idx]["name"]; } + if(e131_settings["devices"][device_idx].contains("ip")) + { + dev.ip = e131_settings["devices"][device_idx]["ip"]; + } + if(e131_settings["devices"][device_idx].contains("num_leds")) { dev.num_leds = e131_settings["devices"][device_idx]["num_leds"]; @@ -188,40 +194,56 @@ void DetectE131Controllers(std::vector &rgb_controllers) \*---------------------------------------------------------*/ bool device_added_to_existing_list = false; - for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++) + /*---------------------------------------------------------*\ + | Only track grouping for multicast controllers. Unicast | + | controllers are currently not grouped. | + \*---------------------------------------------------------*/ + if(dev.ip == "") { - for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++) + for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++) { - /*---------------------------------------------------------*\ - | 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(dev.start_universe == device_lists[list_idx][device_idx].start_universe) + for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++) + { + /*---------------------------------------------------------*\ + | 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(dev.start_universe == device_lists[list_idx][device_idx].start_universe) + { + device_lists[list_idx].push_back(dev); + device_added_to_existing_list = true; + break; + } + } + + if(device_added_to_existing_list) { - device_lists[list_idx].push_back(dev); - device_added_to_existing_list = true; break; } } - if(device_added_to_existing_list) + /*---------------------------------------------------------*\ + | If the device did not overlap with existing devices, | + | create a new list for it | + \*---------------------------------------------------------*/ + if(!device_added_to_existing_list) { - break; + std::vector new_list; + + new_list.push_back(dev); + + device_lists.push_back(new_list); } } - - /*---------------------------------------------------------*\ - | If the device did not overlap with existing devices, | - | create a new list for it | - \*---------------------------------------------------------*/ - if(!device_added_to_existing_list) + else { - std::vector new_list; + std::vector tmp_device_list; + tmp_device_list.push_back(dev); - new_list.push_back(dev); - - device_lists.push_back(new_list); + RGBController_E131* rgb_controller; + rgb_controller = new RGBController_E131(tmp_device_list); + rgb_controllers.push_back(rgb_controller); } } diff --git a/Controllers/E131Controller/RGBController_E131.cpp b/Controllers/E131Controller/RGBController_E131.cpp index 885889e3..ceecdc65 100644 --- a/Controllers/E131Controller/RGBController_E131.cpp +++ b/Controllers/E131Controller/RGBController_E131.cpp @@ -15,6 +15,8 @@ using namespace std::chrono_literals; RGBController_E131::RGBController_E131(std::vector device_list) { + bool multicast = false; + devices = device_list; name = "E1.31 Device Group"; @@ -34,9 +36,17 @@ RGBController_E131::RGBController_E131(std::vector device_list) /*-----------------------------------------*\ | Append the destination address to the | - | location field (multicast only for now) | + | location field | \*-----------------------------------------*/ - location += "Multicast, "; + if((devices.size() == 1) && (devices[0].ip != "")) + { + location += "Unicast " + devices[0].ip + ", "; + } + else + { + location += "Multicast, "; + multicast = true; + } /*-----------------------------------------*\ | Calculate universe list | @@ -152,7 +162,15 @@ RGBController_E131::RGBController_E131(std::vector device_list) e131_addr_t dest_addr; e131_pkt_init(&packet, universe, 512); - e131_multicast_dest(&dest_addr, universe, E131_DEFAULT_PORT); + + if(multicast) + { + e131_multicast_dest(&dest_addr, universe, E131_DEFAULT_PORT); + } + else + { + e131_unicast_dest(&dest_addr, devices[0].ip.c_str(), E131_DEFAULT_PORT); + } packets.push_back(packet); universes.push_back(universe); diff --git a/Controllers/E131Controller/RGBController_E131.h b/Controllers/E131Controller/RGBController_E131.h index 69f2dcff..94c41839 100644 --- a/Controllers/E131Controller/RGBController_E131.h +++ b/Controllers/E131Controller/RGBController_E131.h @@ -42,6 +42,7 @@ typedef unsigned int e131_matrix_order; struct E131Device { std::string name; + std::string ip; unsigned int num_leds; unsigned int start_universe; unsigned int start_channel;