diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 753d5a9..3fc8236 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -3,14 +3,15 @@ include(FetchContent) FetchContent_Declare( gnuradio4 GIT_REPOSITORY https://github.com/fair-acc/gnuradio4.git - GIT_TAG c51a5d5253bdd2ce7bbc785970b7ec4bbe2878dc # main as of 2024-06-14 + #GIT_TAG 6d85d74a09194f30e538f1a87e586944a6aae86d # main as of 2024-09-16 + GIT_TAG frank/upgrade-fmt-11.0.2 SYSTEM ) FetchContent_Declare( opencmw-cpp GIT_REPOSITORY https://github.com/fair-acc/opencmw-cpp.git - GIT_TAG 0fb3758c3ffe7707aa5e0bd2ad25f9e8fb19f79d # main as of 2024-04-26 + GIT_TAG frank/upgrade-fmt-11.0.2 SYSTEM ) diff --git a/src/service/gnuradio/GnuRadioWorker.hpp b/src/service/gnuradio/GnuRadioWorker.hpp index 2b2eb97..c8849e1 100644 --- a/src/service/gnuradio/GnuRadioWorker.hpp +++ b/src/service/gnuradio/GnuRadioWorker.hpp @@ -314,7 +314,7 @@ class GnuRadioAcquisitionWorker : public Worker>(std::move(*pendingFlowGraph)); + auto sched = std::make_unique>(std::move(*pendingFlowGraph)); toScheduler = std::make_unique(); fromScheduler = std::make_unique(); std::ignore = toScheduler->connect(sched->msgIn); @@ -417,8 +417,8 @@ class GnuRadioAcquisitionWorker : public Worker #include -#include +#include #ifndef __EMSCRIPTEN__ #include diff --git a/src/ui/App.hpp b/src/ui/App.hpp index b6d2dac..d093632 100644 --- a/src/ui/App.hpp +++ b/src/ui/App.hpp @@ -11,6 +11,7 @@ #include "FlowgraphItem.hpp" #include "OpenDashboardPage.hpp" +#include #include #include @@ -117,7 +118,8 @@ class App { std::string_view uniqueName() const override { return _scheduler.unique_name; } void sendMessage(const gr::Message& msg) final { - _toScheduler.streamWriter().publish([&](auto& output) { output[0] = msg; }, 1); + auto output = _toScheduler.streamWriter().reserve(1UZ); + output[0] = msg; } void handleMessages(FlowGraph& fg) final { @@ -200,7 +202,7 @@ class App { template void assignScheduler(Graph&& graph) { - using Scheduler = gr::scheduler::Simple; + using Scheduler = gr::scheduler::Simple; _scheduler.emplace(std::forward(graph), schedulerThreadPool); } diff --git a/src/ui/Flowgraph.cpp b/src/ui/Flowgraph.cpp index 739779c..d9b65d7 100644 --- a/src/ui/Flowgraph.cpp +++ b/src/ui/Flowgraph.cpp @@ -280,10 +280,10 @@ void Block::setCurrentInstantiation(const std::string& newInstantiation) { m_outputs.reserve(instantiation.outputs.size()); m_inputs.reserve(instantiation.inputs.size()); for (auto& o : instantiation.outputs) { - m_outputs.push_back({this, o.type, o.dataset, Port::Direction::Output}); + m_outputs.push_back({this, o.name, o.type, o.dataset, Port::Direction::Output}); } for (auto& o : instantiation.inputs) { - m_inputs.push_back({this, o.type, o.dataset, Port::Direction::Input}); + m_inputs.push_back({this, o.name, o.type, o.dataset, Port::Direction::Input}); } } @@ -337,22 +337,55 @@ void FlowGraph::parse(const std::string& str) { return it == m_blocks.end() ? nullptr : it->get(); }; + auto findPort = [&](const auto& portDefinition, auto& ports) { + return std::visit(gr::meta::overloaded( + [&](const gr::PortDefinition::IndexBased& definition) { + if (definition.topLevel >= ports.size()) { + fmt::println(std::cerr, "Cannot connect, index {} is not valid (only {} ports available)", definition.topLevel, definition.topLevel); + } + // TODO check subIndex once we support port collections + return std::pair{ports.begin() + definition.topLevel, definition.subIndex}; + }, + [&](const gr::PortDefinition::StringBased& definition) { + auto split = std::string_view(definition.name) | std::ranges::views::split('#'); + const auto segs = std::vector(split.begin(), split.end()); + const auto name = std::string_view(segs[0].data(), segs[0].size()); + const auto subIndex = [&] { + if (segs.size() < 2) { + return 0UZ; + } + auto index = 0UZ; + const auto& [_, ec] = std::from_chars(segs[1].begin(), segs[1].end(), index); + if (ec != std::errc{}) { + throw std::runtime_error(fmt::format("Invalid subindex in '{}'", definition.name)); + } + return index; + }(); + const auto it = std::ranges::find_if(ports, [&name](const auto& port) { return port.name == name; }); + if (it == ports.end()) { + fmt::println(std::cerr, "Cannot connect, no port with name '{}'", name); + } + + // TODO check subIndex once we support port collections + + return std::pair{it, subIndex}; + }), + portDefinition.definition); + }; + graph.forEachEdge([&](const auto& edge) { auto srcBlock = findBlock(edge._sourceBlock->uniqueName()); assert(srcBlock); - const auto sourcePort = edge._sourcePortDefinition.topLevel; - auto dstBlock = findBlock(edge._destinationBlock->uniqueName()); + // TODO do not ignore subindexes + const auto& [srcPort, _] = findPort(edge.sourcePortDefinition(), srcBlock->m_outputs); + auto dstBlock = findBlock(edge._destinationBlock->uniqueName()); assert(dstBlock); - const auto destinationPort = edge._destinationPortDefinition.topLevel; - // TODO support port collections + const auto& [dstPort, _] = findPort(edge.destinationPortDefinition(), dstBlock->m_inputs); - if (sourcePort >= srcBlock->m_outputs.size()) { - fmt::print("ERROR: Cannot connect, no output port with index {} in {}, have only {} ports\n", sourcePort, srcBlock->m_uniqueName, srcBlock->m_outputs.size()); - } else if (destinationPort >= dstBlock->m_inputs.size()) { - fmt::print("ERROR: Cannot connect, no input port with index {} in {}, have only {} ports\n", destinationPort, dstBlock->m_uniqueName, dstBlock->m_inputs.size()); - } else { - connect(&srcBlock->m_outputs[sourcePort], &dstBlock->m_inputs[destinationPort]); + if (srcPort == srcBlock->m_outputs.end() || dstPort == dstBlock->m_inputs.end()) { + return; } + connect(&*srcPort, &*dstPort); }); m_graphChanged = true; diff --git a/src/ui/Flowgraph.hpp b/src/ui/Flowgraph.hpp index 069bbd9..e269dc0 100644 --- a/src/ui/Flowgraph.hpp +++ b/src/ui/Flowgraph.hpp @@ -263,6 +263,7 @@ class Block { }; Block* owningUiBlock; + const std::string name; const std::string rawPortType; bool isDataset; const Direction portDirection; diff --git a/src/ui/cmake/Dependencies.cmake b/src/ui/cmake/Dependencies.cmake index 159e922..7678f40 100644 --- a/src/ui/cmake/Dependencies.cmake +++ b/src/ui/cmake/Dependencies.cmake @@ -47,14 +47,14 @@ FetchContent_Declare( # needed to load images in ImGui FetchContent_Declare( opencmw-cpp GIT_REPOSITORY https://github.com/fair-acc/opencmw-cpp.git - GIT_TAG 0fb3758c3ffe7707aa5e0bd2ad25f9e8fb19f79d# main as of 2024-04-26 + GIT_TAG frank/upgrade-fmt-11.0.2 SYSTEM ) FetchContent_Declare( gnuradio4 GIT_REPOSITORY https://github.com/fair-acc/gnuradio4.git - GIT_TAG c51a5d5253bdd2ce7bbc785970b7ec4bbe2878dc # main as of 2024-06-14 + GIT_TAG frank/upgrade-fmt-11.0.2 SYSTEM )